Page 1 of 1

Premature end of JPEG file - Corrupt JPEG

Posted: Thu Aug 03, 2006 5:15 pm
by permaguest
Hello!

I've been getting this error:

Code: Select all

recoverable error: imagecreatefromjpeg() : gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file on line 18
I think it is because the images in question are corrupted. (I get a notice from GIMP 2 that the image is corrupted).

The problem is this:

A) There are over 7000 images, so I can't change them by hand.
B) I don't want to pay for image correction software.

I've got

PHP Version 5.2.0RC2-dev
GD (2.0.28 compatible)
Apache/2.2.2 (Win32)

I also have gd.jpeg_ignore_warning set to 1, and uncommented in php.ini

Code: Select all

<?php
header('Content-type: image/jpeg');
$file = $_GET['imagename'];
$maxheight= $_GET['maxheight'];
list($width, $height) = getimagesize($file);
if(is_numeric($maxheight))
{
    $ratio = $maxheight / $height;
}
else
{
    $ratio = 1;
}
$modwidth = $width * $ratio;
$modheight = $height * $ratio;
$tn= imagecreatetruecolor($modwidth, $modheight);
$source = imagecreatefromjpeg($file);
imagecopyresampled($tn, $source, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn);
?>
Absolutely any help would be appreciated. Been working on this for about 5 hours. I even tried renaming the jpegs to pngs with no result.

Posted: Wed Feb 07, 2007 7:26 am
by anjanesh
Any luck on this. I've been getting this too. IrfanView doesnt show any error, but I could save it again with no errors but this is not possible to manually save 1000's of jpg. Is there any command-line tool to do the job ?

Code: Select all

[07-Feb-2007 10:30:34] PHP Warning:
imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file
 in C:\www\test\gd.class.php on line 19
Thanx

Posted: Wed Feb 07, 2007 1:50 pm
by feyd
This thread was last updated six months ago.. let it stay dead.