Page 1 of 1

imagecreatetruecolor() and Resize

Posted: Wed Feb 14, 2007 3:07 pm
by AliasBDI
I was hoping to use the imagecreatetruecolor() function to overcome my current problem. I am using this script to resize my uploaded images. However, they are compressing the files far too much even with it set to 100 quality in the upload jpg. So does anyone have any idea as to how I can implement imagecreatetruecolor() to get better quality on this following code?

Code: Select all

$dest_x = 500;
$dest_y = 400;
if (imagesx($i) > $dest_x or imagesy($i) > $dest_y) {
	if (imagesx($i) >= imagesy($i)) {
		$img_x = $dest_x;
		$img_y = imagesy($i)*($dest_x/imagesx($i));
	} else {
		$img_x = imagesx($i)*($dest_y/imagesy($i));
		$img_y = $dest_y;
	}
} else {
	$img_x = imagesx($i);
	$img_y = imagesy($i);
}
$img = imagecreate($img_x,$img_y);
imagecopyresampled($img, $i,0, 0, 0, 0, $img_x, $img_y, imagesx($i), imagesy($i));
if ($typeID==1) { // is jpg
	$imageNewName = $acctFirstName."_".$newID.".jpg";
	imagejpeg($img, "../eControl_repository/File/Accounts/".$imageNewName, 100);
} elseif ($typeID==2) { // is gif
	$imageNewName = $acctFirstName."_".$newID.".gif";
	imagegif($img, "../eControl_repository/File/Accounts/".$imageNewName);
}

Posted: Wed Feb 14, 2007 4:19 pm
by onion2k
Just replace imagecreate() with imagecreatetruecolor().

Posted: Wed Feb 14, 2007 4:35 pm
by AliasBDI
Worked perfectly - thanks!