|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
2 + 42 = ?
Subscribe to this entry?

 [2006-12-21 02:34 UTC] hnthanhphong at yahoo dot com
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 

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-12-21 09:23 UTC]
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]
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]
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);
 // code to resize an image
 return false;
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 21 03:01:27 2024 UTC