php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50125 imagecreatefromjpeg(): "not a valid JPEG file"
Submitted: 2009-11-09 15:01 UTC Modified: 2009-11-17 20:24 UTC
From: vhaban at atlas dot cz Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.3.1RC3 OS: Fedora 11 x86 64bit
Private report: No CVE-ID: None
 [2009-11-09 15:01 UTC] vhaban at atlas dot cz
Description:
------------
I am not able to open jpeg files using imagecreatefromjpeg function and still get this: Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'x.jpg' is not a valid JPEG file in ...

But it seems that it is not the problem of current PHP version, because it behaves the same with 5.2.9. I have examined both internal and external GD library still with the same result.

I have tried gd.jpeg_ignore_warning and also the bug with invalid return type is already solved in 5.3.1RC3.

It seems to be rather some compilation error specific to 64 bit Fedora. But no errors are reported during compilation and everything seems to be fine, imagecreatefrompng() is doing perfectly, for example, and the jpeg images are not corrupted.

Thank you for any help. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-10 10:26 UTC] jani@php.net
You need to provide the problematic jpeg file. For me this works just fine on Fedora 11 / 64bit.
 [2009-11-10 11:46 UTC] vhaban at atlas dot cz
As I have already mentioned, it is not the problem of JPEG files themselves, because it cannot open any JPEG file. If I create a fresh new JPEG file in GIMP and try to open it, GD fails. If I convert a PNG into JPEG, it fails. The files can be opened in any editor, viewer without problems. The problem seems to be somewhere in the unability to properly detect the file type. But the problem with invalid return type should be already solved in PHP 5.3.1RC3 and I have checked the file and it seems to be as it should be. But there seems to be some other similar bug.
 [2009-11-10 12:18 UTC] vhaban at atlas dot cz
I have compiled GD with libjpeg 6.2 and 7 and both behave the same. However, phpinfo reports the version of libjpeg as unknown. Is this correct? When I use internal GD, then it reports 2.0.34. When I use external compiled GD, then there is just 2.
 [2009-11-10 12:24 UTC] pajoye@php.net
jpeg7 only format is not supported when the jpeg6 library is used.

I think you are just mixing formats, all latest php releases work just fine with all jpeg I have here.

Btw, you should not use the external GD, I recomment to use the bundled version only.

no bug > bogus. Unless you can clearly reproduce it and provide us a file as well.
 [2009-11-16 20:19 UTC] vhaban at atlas dot cz
I am running also PHP 5.3.0 on an old Fedora Core 6 x86_64 machine with an AMD64 processor and it is working well even with the return type bug. But the machine with Fedora 11 is a Core 2 Duo notebook.

Firstly, I compile jpeg-7:
./configure --prefix=/usr/share/jpeg-7
make
make install

Secondly, I compile PHP with internal GD:
./configure --with-apxs2=/etc/httpd/bin/apxs --with-libdir=lib64 --with-gd --with-jpeg-dir=/usr/share/jpeg-7/lib --with-png-dir --with-xsl
make
make install

phpinfo() tells about the gd this:
gd
GD Support 	enabled
GD Version 	bundled (2.0.34 compatible)
GIF Read Support 	enabled
GIF Create Support 	enabled
JPEG Support 	enabled
libJPEG Version 	unknown
PNG Support 	enabled
libPNG Version 	1.2.37
WBMP Support 	enabled
XBM Support 	enabled

Directive	Local Value	Master Value
gd.jpeg_ignore_warning	1	0

The code source is:
<?php
ini_set("memory_limit","384M");
ini_set("gd.jpeg_ignore_warning",1);
$img = imagecreatefromjpeg("img/gdtest.jpg");
phpinfo();
?>

The image is an empty jpeg file created with GIMP.
GIMP Image properties tells:
640 ? 400 pixels, RGB color, JPEG image, etc.

What I get when I run the script is:
Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /.../phpinfo.php on line 4

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'img/gdtest.jpg' is not a valid JPEG file in /.../phpinfo.php on line 4

Where ... is the full path to the script.

I can also send the jpeg image, but I think that the problem is somewhere else.
Thank you for any further help.
 [2009-11-16 20:37 UTC] vhaban at atlas dot cz
After PHP compilation I also run:
libtool --finish /root/install/www/php/php-5.3.1RC3/libs

I also do the restart of Apache:
/etc/httpd/bin/apachectl restart

The above mentioned configuration might be wrong in --with-jpeg-dir=/usr/share/jpeg-7/lib, but I have tried it also without the lib at the end and the result seems to be the same.

Thanks.
 [2009-11-17 18:39 UTC] vhaban at atlas dot cz
So, I have found the possible cause of all this. In httpd/logs/error_log I have got this message:

Wrong JPEG library version: library is 62, caller expects 70

The library seems to be badly configured somewhere. I will report more when I find the cause.
 [2009-11-17 19:15 UTC] vhaban at atlas dot cz
I have found the cause of libjpeg version mixture, but the problem with unability to open jpeg images remains.

The symbolic link /usr/lib64/libjpeg.so was set to 6.2 version file, I had to do:

rm /usr/lib64/libjpeg.so
ln -s /usr/share/jpeg-7/lib/libjpeg.so.7.0.0 /usr/lib64/libjpeg.so

Now there is no error message in /etc/httpd/logs/error_log, but I still cannot open the jpeg files with the same result as described above.
 [2009-11-17 19:30 UTC] vhaban at atlas dot cz
I tried to recompile PHP now and got this error when running configure with the same parameters as above:

configure: error: GD build test failed. Please check the config.log for details.

And the config.log contains this at the end:

configure:35769: checking for jpeg_read_header in -ljpeg
configure:36070: checking for png_write_image in -lpng
configure:43319: gcc -o conftest -g -O2 -fvisibility=hidden   conftest.c    -lpng -lz -ljpeg -lm -ldl -lnsl  -lxml2 -lz -lm -lxml2 -lz -lm 1>&5
configure: failed program was:
#line 43308 "configure"
#include "confdefs.h"

    char foobar () {}
    char foobar();
    int main() {
      foobar();
      return 0;
    }
 [2009-11-17 20:05 UTC] vhaban at atlas dot cz
I tried to compile PHP with external GD. 

To ease the use of external GD I did first:

cp /usr/share/gd/include/* /usr/share/gd/lib

Then I did:

./configure --with-apxs2=/etc/httpd/bin/apxs --with-libdir=lib64 --with-gd=/usr/share/gd/lib --with-jpeg-dir=/usr/share/jpeg-7 --with-png-dir --with-xsl

But I got this error when running make:

Generating phar.php
/root/install/www/php/php-5.3.1RC3/sapi/cli/php: error while loading shared libraries: libjpeg.so.7: cannot open shared object file: No such file or directory
make: *** [ext/phar/phar.php] Error 127

So I tried this:
ln -s /usr/share/jpeg-7/lib/libjpeg.so.7.0.0 /usr/lib64/libjpeg.so.7

Then the make was successfull with one ignored error:

Generating phar.phar
chmod: cannot access `ext/phar/phar.phar': No such file or directory
make: [ext/phar/phar.phar] Error 1 (ignored)

Build complete.
Don't forget to run 'make test'.

I did make install, finished the libraries with libtool, still with the ignored error about missing phar.phar.

AND NOW IT IS WORKING!!!

SOLVED, BUT ONLY WITH THE EXTERNAL GD!
 [2009-11-17 20:24 UTC] vhaban at atlas dot cz
So, I hope, that this mine explanation helps at least someone. The external GD is now working well, all my jpegs can be opened and the app runs well. But I still cannot get working the built-in GD. The external is 2.0.35, the built-in is 2.0.34. Is the above mentioned configure error with the built-in GD a bug or am I doing something wrong?

Thank you very much for your patience!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 19:01:29 2024 UTC