php.net |  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
Description:
------------
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: http://beta.opajaap.nl/upload-test-page/


Test script:
---------------
<?php 
$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


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-14 13:24 UTC] cmb@php.net
-Status: Open +Status: Feedback
 [2016-06-14 13:24 UTC] cmb@php.net
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:
http://beta.opajaap.nl/wp-content/uploads/wppa-source/14659120613561390699243.jpg
 [2016-06-14 15:57 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-06-14 15:57 UTC] cmb@php.net
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] cmb@php.net
-Status: Assigned +Status: Feedback
 [2016-06-15 00:02 UTC] cmb@php.net
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] <http://php.net/manual/en/image.configuration.php#ini.image.jpeg-ignore-warning>
[2] <http://php.net/manual/en/function.exif-read-data.php>
[3] <http://sylvana.net/jpegcrop/exif_orientation.html>
 [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] cmb@php.net
-Assigned To: cmb +Assigned To: pajoye
 [2016-06-15 09:57 UTC] cmb@php.net
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
<https://github.com/libgd/libgd/blob/gd-2.2.1/src/gd_jpeg.c#L413-L416>.
 [2016-06-15 11:05 UTC] pajoye@php.net
Go ahead for 7.1+
 [2016-06-15 12:04 UTC] cmb@php.net
I've submitted a respective PR:
<https://github.com/php/php-src/pull/1945>.
 [2016-07-03 06:03 UTC] pajoye@php.net
-Assigned To: pajoye +Assigned To: cmb
 [2016-07-03 06:03 UTC] pajoye@php.net
Go ahead and merge it :)
 [2016-07-03 10:47 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2016-07-03 10:47 UTC] cmb@php.net
Merged.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC