|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72404 imagecreatefromjpeg fails on selfie
Submitted: 2016-06-14 12:51 UTC Modified: 2016-07-03 10:47 UTC
From: opajaap at opajaap dot nl Assigned: cmb (profile)
Status: Closed Package: GD related
PHP Version: Irrelevant OS: SunOS localhost 5.10 Generic_142
Private report: No CVE-ID: None
 [2016-06-14 12:51 UTC] opajaap at opajaap dot nl
PHP version 7.06 ( and others )

On executing imagecreatefromjpeg() with a valid jpg image file created by the front-end camera of a samsung galaxy grand prime ( android ) smartphone, the function returns false.
Using the normal - back-end - camera with a higher resolution, gives no problem.

The photo works correctly on the phone and on a windows 10 laptop.

The server error log says:

PHP Warning:  imagecreatefromjpeg(): '/mnt/webc/d3/15/51893315/htdocs/opajaap/beta/wp-content/uploads/wppa-source/album-256/20160614_125550.jpg' is not a valid JPEG file in /mnt/webc/d3/15/51893315/htdocs/opajaap/beta/wp-content/plugins/wp-photo-album-plus/wppa-photo-files.php on line 87

This is reproduceable also with a samsung galaxy s7

You can testit here:

Test script:
$file = {pathname to jpg photo taken by the front camera of a samsung smartphone};
$image = imagecreatefromjpeg( $file );
if ( ! $image ) {
echo 'Failed';
Prints Failed while the jpg is a valid jpg file


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 13:24 UTC]
-Status: Open +Status: Feedback
 [2016-06-14 13:24 UTC]
Please provide a link to download such a JPEG file.
 [2016-06-14 15:44 UTC] opajaap at opajaap dot nl
-Status: Feedback +Status: Open
 [2016-06-14 15:44 UTC] opajaap at opajaap dot nl
Link to image:
 [2016-06-14 15:57 UTC]
-Assigned To: +Assigned To: cmb
 [2016-06-14 15:57 UTC]
Thanks for the link. Calling imagecreatefromjpeg() on this image
gives me an additional warning:

> imagecreatefromjpeg(): gd-jpeg, libjpeg: recoverable error:
> Invalid SOS parameters for sequential JPEG

Have to investigate further.
 [2016-06-15 00:02 UTC]
-Status: Assigned +Status: Feedback
 [2016-06-15 00:02 UTC]
Setting gd.jpeg_ignore_warning=1 in php.ini solved the problem
that the JPEG couldn't be read. Please verify this[1].

If that works, you'll find that the image is bottom up when read
by GD. That is because the image data are stored that way, and the
Exif Orientation flag is supposed to signal a reader that the
image has to rotated by 180° (its value is 3[2][3]). However, GD
is not supposed to regard Exif data, so you'd have to rotate the
image yourself if necessary.

[1] <>
[2] <>
[3] <>
 [2016-06-15 09:13 UTC] opajaap at opajaap dot nl
-Status: Feedback +Status: Assigned
 [2016-06-15 09:13 UTC] opajaap at opajaap dot nl
Thank you.

ini_set( 'gd.jpeg_ignore_warning', true );

is an acceptable workaround.

Orientation is not a problem, I can handle exif and orientations.
 [2016-06-15 09:57 UTC]
-Assigned To: cmb +Assigned To: pajoye
 [2016-06-15 09:57 UTC]
Fine, and thanks for the quick feedback.

@pierre Wouldn't it make sense to ignore those warnings by
*default* (i.e. gd.jpeg_ignore_warning=1)? As I understand it,
that is the default in libgd, see
 [2016-06-15 11:05 UTC]
Go ahead for 7.1+
 [2016-06-15 12:04 UTC]
I've submitted a respective PR:
 [2016-07-03 06:03 UTC]
-Assigned To: pajoye +Assigned To: cmb
 [2016-07-03 06:03 UTC]
Go ahead and merge it :)
 [2016-07-03 10:47 UTC]
-Status: Assigned +Status: Closed
 [2016-07-03 10:47 UTC]
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 30 07:01:30 2024 UTC