I have an image handling script that has the option to either display an image full size, or display a thumbnail of it. For the code, see below.
However, with big images (eg. 1600x1200) the thumbnail generation fails with no error - it generates no output and just stops.
I tried adding debugging messages after each image function call, like imagecreatefromjpeg and so on, but none of those ever got shown either (although when processing a smaller image they would all show fine).
Is it likely that I've exceeded my memory quota when doing this? And if so, why am I not getting any errors back?
Finally, is this something that is hardcoded or can it be changed? I don't host my own site, but I do know the people who run the hosting company I use very well so could probably get them to alter the PHP setup for me if that would fix it.
Thanks.
Script code:
<?php
$httplocation = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['REQUEST_URI']) . "/images/" . $_GET['l'] . ".jpg";
$filelocation = dirname($_SERVER['PATH_TRANSLATED']) . "/images/" . $_GET['l'] . ".jpg";
if ($_GET['t'] == 0) {
header("Content-type: image/jpeg");
header("Location: $httplocation");
}
else if ($_GET['t'] == 1) {
$img = null;
$img = @imagecreatefromjpeg($filelocation);
// If an image was successfully loaded, test the image for size
if ($img) {
// Get image size and scale ratio
$width = imagesx($img);
$height = imagesy($img);
$scale = min(150/$width, 150/$height);
// If the image is larger than the max shrink it
if ($scale < 1) {
$new_width = floor($scale*$width);
$new_height = floor($scale*$height);
// Create a new temporary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// Copy and resize old image into new image
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0,
$new_width, $new_height, $width, $height);
imagedestroy($img);
$img = $tmp_img;
}
}
if (!$img) {
$img = imagecreate(150, 30); // Create a blank image
$bgc = imagecolorallocate($img, 255, 255, 255);
$tc = imagecolorallocate($img, 0, 0, 0);
imagefilledrectangle($img, 0, 0, 150, 30, $bgc);
// Output an errmsg
imagestring($img, 1, 5, 5, "Error loading " . $_GET['l'] . ".jpg", $tc);
}
// Display the image
header("Content-type: image/jpeg");
imagejpeg($img);
}
?>