tags:

views:

79

answers:

3

Any PHP functions that deal with JPEGs don't seem to be working on my server.

This code:

<?php
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
header('Content-type: image/jpeg');
imagejpeg($im);
imagedestroy($im);
?>

creates an empty file.

Using a GIF or PNG function will create an image containing the text "A Simple Text String" as expected.

This:

$im = imagecreatefromjpeg("test.jpg");

returns

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: 'test.jpg' is not a valid JPEG file in /path/to/test.php on line 2

A phpinfo() shows:

gd
GD Support  enabled
GD Version  2.0 or higher
FreeType Support    enabled
FreeType Linkage    with freetype
FreeType Version    2.3.9
T1Lib Support   enabled
GIF Read Support    enabled
GIF Create Support  enabled
JPG Support     enabled
PNG Support     enabled
WBMP Support    enabled 

And the webserver can read any relevant files.

GIF and PNG functions work fine, and as expected.

Any ideas?

EDIT:

Found this in my Apache error log file:

gd-jpeg: JPEG library reports unrecoverable error: Wrong JPEG library version: library is 80, caller expects 62
A: 

It appears that the file test.jpg doesn't exist, or isn't the correct filetype headers (eg, if someone renames a test.png as test.jpg it will still have the .png headers). Try creating a new test.jpg file using an image editing program and see if it works.

Ben
Have tried this, and still not working. Just to confirm that it did exist and I'd got the path right, I tried to open one that was deliberately wrong, and it gave me a different error (Can't open file, or similar)
Oli
+2  A: 

Your error log clearly shows that your PHP is compiled against/requires libjpeg version 62, while the library on your server is version 80.

Either install the correct version of libjpeg, or recompile gd/php.

gnud
apt-get tells me that "libjpeg62-dev is already the newest version"
Oli
libjpeg62 is the library, libjpeg62-dev are just headers. Also, are you using the standard php/gd packages?
gnud
Yes, standard as installed by "apt get install"
Oli
A: 

There must be something wrong with your install because it works fine for me...

Mark