Forum Moderators: coopster

Message Too Old, No Replies

Help with Image check PHP

         

tripc1

3:08 am on Jul 20, 2009 (gmt 0)

10+ Year Member



I want to check if the image isn't empty.

For example:
That one isn't fully uploaded, so we don't need it
(if you can see there is blank space in the bottom of the picture):
<snipped image>
or like that one:
<snipped image>

But that one is fully uploaded, so we need it:
<snipped image>

There is anyway to check if the image is fully uploaded or not?
I hope you understand what I mean.

Sorry if my English isn't good.

Thanks in advance.

[edited by: coopster at 8:45 pm (utc) on July 27, 2009]
[edit reason] removed external image links [/edit]

vincevincevince

4:55 am on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



GD (e.g. from within PHP) will throw the following error when you try to use imagecreatefromjpeg:

imagecreatefromjpeg() : gd-jpeg, libjpeg: recoverable error: Premature end of JPEG

Catch the error, and if found then it means you can unlink() the file.

tripc1

9:36 am on Jul 21, 2009 (gmt 0)

10+ Year Member



can you show me an exmaple?

[edited by: tripc1 at 9:46 am (utc) on July 21, 2009]

vincevincevince

9:41 am on Jul 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That would be to do your work for you! However, the outline is this:


function delete_if_broken($imgname)
{
if (!$im=imagecreatefromjpeg($imgname)) unlink($imgname);
imagedestroy($im);
}

tripc1

9:55 am on Jul 21, 2009 (gmt 0)

10+ Year Member



hmmm that doesn't work.

function delete_if_broken($imgname)
{
if (!$im=imagecreatefromjpeg($imgname)) unlink($imgname);
imagedestroy($im);
}

header('Content-type: image/jpeg');
$image = "http://i29.tinypic.com/m8eetv.jpg";
$img = delete_if_broken($image);

imagejpeg($img);
imagedestroy($img);

The function 'imagecreatefromjpeg()' doesn't return error when the image is damaged..
and that picture is fine, but return error..

anything else? =\