Hi,
I was using this little check to see if an uploaded image has the correct
type:

if($img && $img_type != 'image/jpeg'){
$error['img'] = 'image has to be "jpeg"<BR>';
}

but the ImageCreateFromJPEG function in the next script returned:

Warning: imagecreatefromjpeg: '/tmp/1.jpg' is not a valid JPEG file

This seems to happen with images that are kind of corrupted or something, I
am not sure why. Anyhow, I implemented this as an error check instead:

if(!$photo = @ImageCreateFromJPEG($img)){
$error['img'] = 'image is not a valid jpeg file<BR>';
}

This works, but my question is do I have to use 'ImageDestroy' everytime
after I used the 'ImageCreateFromJPEG' function? Would now any tmp files be
clogging up the /tmp directory? Would it suck up memory?

Thanks,
DrTebi

    What version of PHP are you using? I recall ... was it prior to v4.0.5 or 4.0.6? ... that the ImageCreateFromJPEG function was broken, and failed to recognise some JPEGs as valid.

    In that situation, the cure was to upgrade PHP.

    As for your other question, no; the images being manipulated are held in core and not in files (files would be slow) - if you don't call ImageDestroy() the memory they consume will be released when the script ends.

    That said, if you're on a crowded server, it's prolly good etiquette to ImageDestroy no-longer-needed images, since the things can be pretty large (since they are, after all, uncompressed arrays of pixel values). Aside from that, memory's cheap; it's time that's scarce.

      Write a Reply...