PHP GD Incredibly Strange Problem
Posted
by ThinkingInBits
on Stack Overflow
See other posts from Stack Overflow
or by ThinkingInBits
Published on 2010-05-20T05:02:52Z
Indexed on
2010/05/20
5:10 UTC
Read the original article
Hit count: 165
if ($img = imagecreatefromjpeg("/var/www/images/upload/1/1.jpg")) {
die("success");
}
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");
}
The first if statement dies and echos success. If I take out the first if statement, the second one echos "image could not be created or saved"
If honestly run out of ideas on this one, the code is identical
© Stack Overflow or respective owner