I hate to post this note, but I can't find a solution and I've read many, many threads here about this. I'm hoping somebody might have a nugget of info to help me out on this.
I've hacked together a function for uploading a file and then resizing it - it fails on imagecreatetruecolor. I have GD2.0.15 installed and enabled and permissions are turned on - so I'm really at a loss as this is a pretty easy script.
Oh yes, if I take out the imagecreatetruecolor line it works, but it won't resize the images...
Any ideas? Thanks...v
function imgSizing($dir, $name, $quality, $maxwidth, $maxheight, $type) {
$image = "$dir/$name";
$input_image = imagecreatefromjpeg($image);
$imgwidth = imagesx($input_image);
$imgheight = imagesy($input_image);
$ratio = $imgheight / $imgwidth;
if ($imgwidth > $imgheight) {
$ratio = $maxwidth / $imgheight;
$newwidth = $maxwidth;
$newheight = round($imgheight * ratio);
} else if ($imgwidth < $imgheight) {
$ratio = $maxheight / $imgheight;
$newwidth = round($imgwidth * $ratio);
$newheight = $maxheight;
} else {
$newwidth = $imgwidth;
$newheight = $imgheight;
}
$output_image = imagecreatefromjpeg($image);
// it's failing here...Error 1
$output_image = imagecreatetruecolor($newwidth,$newheight) or die ("Error - 1");
imagecopyresampled($output_image,$input_image,0,0,0,0,$newwidth,$newheight,$imgwidth,$imgheight) or die ("Error - 2");
if ($type == "thumb") {
$dest = "$dir" . "/th-" . "$name"; } else { $dest = "$dir/$name"; }
imagejpeg($output_image, $dest, $quality);
imagedestroy($input_image);
imagedestroy($output_image);
}