imagecreatetruecolor() and Resize

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

imagecreatetruecolor() and Resize

Post 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);
}
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Just replace imagecreate() with imagecreatetruecolor().
AliasBDI
Forum Contributor
Posts: 286
Joined: Fri Nov 15, 2002 10:35 am
Location: Spring, TX, USA

Post by AliasBDI »

Worked perfectly - thanks!
Post Reply