I have a script that is supposed to take an image URL from a database and resize the image down to thumbnail size and output it. It works fine on one server, but not on a new one I'm trying to build.
The working server is:
RH Linux 8.0
Apache 2.0.47
PHP 4.3.3
--GD: bundled (2.0.15 compatible)
--JPG support: enabled
The new server is:
RH Linux 9.0
Apache 2.0.49
PHP 4.3.6
--GD: bundled (2.0.22 compatible)
--JPG support: enabled
The script seems to runs fine but the image does not display. In Mozilla, the error 'The image "createthumb.php?id=1" could not be displayed, because it contains errors' and in IE you get the red X.
If you remove the Header() line, you see all the usual jibberish that starts with "ÿØÿà CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality".
I've tried using png instead of jpeg, no go. I can also confirm the url its getting from the db exists and is a valid image (and are the same as the ones on the working server).
No errors anywhere. If I add the "error_reporting(E_ALL)' line, it doesn't pull anything either. I'm at a loss here.
Any ideas?
Here's the script:
<?php
/*createthumb.php
* Creates thumbnails of files
* requires GD
*
*/
include 'db.php';
$productimgbase="images/products/";
$db=dbconnect();
$id = $_GET['id'];
if (isset($_GET['size']))
$size= $_GET['size'];
else
$size=100;
$result=mysql_query("SELECT imageurl from products where id = $id");
$data=trim(mysql_result($result,0,"imageurl"));
if ($data==null){
$data="blank.jpg";
}
$ext=strtolower(substr($data, strlen($data)-3, 3));
switch ($ext){
case "jpg": $type="pjpeg";
$src=imagecreatefromjpeg($productimgbase.$data);
break;
case "png": $type="x-png";
$src=imagecreatefrompng($productimgbase.$data);
break;
}
Header ("Content-type: image/pjpeg");
$width=imagesx($src);
$height=imagesy($src);
$aspect_ratio=$height/$width;
if ($width <= $size){
$new_w=$width;
$new_h=$height;
}else {
$new_w=$size;
$new_h=abs($new_w * $aspect_ratio);
}
$img = imagecreatetruecolor($new_w,$new_h);
imagecopyresized($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
if ($type == "pjpeg") {
imagejpeg($img);
}
else if ($type == "x-png") {
imagepng($img);
}
imagedestroy($img);
?>