Premature end of JPEG file - Corrupt JPEG

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
permaguest
Forum Newbie
Posts: 1
Joined: Thu Aug 03, 2006 5:00 pm

Premature end of JPEG file - Corrupt JPEG

Post 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.
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This thread was last updated six months ago.. let it stay dead.
Post Reply