Trouble with php imaging

I’d like to do some cool things with images using php but first, I have to find out why simple php image functions don’t work for me.

I tried:
$size = getimagesize("/image.png");
but I get an error:
Warning: getimagesize(/image.png) [function.getimagesize]: failed to open stream: No such file or directory in…

I don’t know what is going wrong since image.png does exist in the directory. I get this error for every php image function I try.

Thanks for the help!

Remember that the output of the function is an array, so that your code snippet, if followed by an “echo $size;” line, will produce no useful information (it will just print “Array”")

I can’t duplicate your error - it seems to work fine for me, so I can only assume that there is some problem with your parameter “filename”.

All the typical suspects come into play here:

is the path correct?
CaSE Matters!
The file must exist in the path referenced.

If you have the file “image.png” in the same directory as your script, you need to loose the “/” before the filename and, in that case, the following code will work (note: ugly, incomplete, and sloppy code follows, only to show the working of the function :wink: ):

<?php list($width, $height, $type, $attr) = getimagesize("image.png"); echo "<img src=\"image.png\" $attr alt=\"getimagesize() example\" />,<br />"; echo "$width <br />" ; echo "$height <br />" ; echo "$type <br />"; echo "$attr <br />"; ?> Here is that code demonstrated working, with a different image.


That was the problem. The file and script were in the same path so I didn’t need the /.

No problem, you are welcome and I glad you got it sorted out (now, off to delete that ugly “quick and dirty” code sample!) :wink: