Problem with php GD image not creating
Posted
by ThinkingInBits
on Stack Overflow
See other posts from Stack Overflow
or by ThinkingInBits
Published on 2010-05-19T22:26:28Z
Indexed on
2010/05/19
22:30 UTC
Read the original article
Hit count: 158
With the following code, my browser is returning 'image not created or saved'. I assure you the location of the image exists. So the line within the if statement is returning false for some reason, and yes GD is installed. Any ideas?
if ($img = @imagecreatefromjpeg("/var/www/images/upload/1/1.jpg")) {
$image_width = imagesx($img);
$image_height = imagesy($img);
$target_width = 150;
$target_height = 150;
if ($image_width > $image_height) {
$percentage = ($target_width / $image_width);
} else {
$percentage = ($target_height / $image_height);
}
$new_image_width = round($image_width * $percentage);
$new_image_height = round($image_height * $percentage);
$imgResized = imagecreatetruecolor($new_image_width, $new_image_height);
imagecopyresampled($imgResized, $img, 0, 0, 0, 0, $new_image_width, $new_image_height, $image_width, $image_height);
imagejpeg($imgResized, $this->path, 100);
imagedestroy($img);
imagedestroy($imgResized);
$this->storeThumbnailLocation();
} else {
die ("image was not created or saved");
}
© Stack Overflow or respective owner