php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39918 imagecreatefromjpeg doesn't work
Submitted: 2006-12-21 02:34 UTC Modified: 2006-12-22 02:10 UTC
From: hnthanhphong at yahoo dot com Assigned: pajoye (profile)
Status: Not a bug Package: GD related
PHP Version: 5.2.0 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hnthanhphong at yahoo dot com
New email:
PHP Version: OS:

 

 [2006-12-21 02:34 UTC] hnthanhphong at yahoo dot com
Description:
------------
I use PHP 5.2 and GD version bundled (2.0.28 compatible). When I use function imagecreatefromjpeg to create a thumbnail but it doesn't work with only one jpeg file. I don't know why?
You can get this jpeg file from http://www.vietmy.com.vn/tmp/test.jpg 

Actual result:
--------------
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Corrupt JPEG data: 321 extraneous bytes before marker 0xd9 in C:\Source\lib\lib.php on line 129

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'C:\ModelMayhem\Source/userphotos/8_48_R.JPG' is not a valid JPEG file in C:\Source\lib\lib.php on line 129

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-21 09:23 UTC] derick@php.net
The messages already says it:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]:
'C:\ModelMayhem\Source/userphotos/8_48_R.JPG' is not a valid JPEG file
 [2006-12-21 09:26 UTC] hnthanhphong at yahoo dot com
But I open this file in photoshop. It works no problem.
 [2006-12-21 09:43 UTC] derick@php.net
Photoshop also "repairs" broken JPEGs, PHP does not do that, and will never do that. I bet if you re-save it in Photoshop PHP can read it as well.
 [2006-12-21 09:49 UTC] hnthanhphong at yahoo dot com
I re-saved in Photoshop, and post again it works property.
Thank you very much.
 [2006-12-21 12:12 UTC] pajoye@php.net
GD does provide a mechanism to be more tolerant with broken jpeg images.

Using error_reporting(E_ALL); while developing would have told you what's going on. GD did report some errors in the jpeg codec. Some of the jpeg errors are recoverable, like those in this image.

You can change the behaviors of the jpeg codec using gd.jpeg_ignore_warning:

ini_set("gd.jpeg_ignore_warning", 1);
$im = imagecreatefromjpeg("test.jpeg");

$im contains now your image.

 [2006-12-22 02:10 UTC] hnthanhphong at yahoo dot com
ini_set("gd.jpeg_ignore_warning", 1);
This code is useful. Now I can make sure that my page always works.
Thanks you for your help.
 [2014-04-23 10:44 UTC] spam2 at rhsoft dot net
in case of a "recoverable error" i expect that a *WARNING* don't lead in the following code be broken for several reasons:

* it is just a warning and not a fatal error
* read the source image works
* the broken metadata of some cameras are removed in the gd-generated thumbnail
* the current behavior breaks the intention of gd for resize images

$src_img = @imagecreatefromjpeg($src_path);
if($src_img)
{
 // code to resize an image
}
else
{
 return false;
}
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 07:01:28 2024 UTC