November 16, 200916 yr Hi all, I'm doing a simple overlay of a transparent PNG onto a solid background. 'imagecopyresized' does the trick transparency-wise, but obviously the overlaid image is jagged. When using 'imagecopyresampled', everything is smooth but images with transparent backgrounds get a weird noise where the transparency should be. Any ideas? Here comes the code and an example: // Preview image functions // 6a. Generate the preview image background (590x520) $tshirtbackgroundimage = imagecreatefrompng("./shirttemplate.png"); $shirtimagepreview = imagecreatetruecolor(590,520); imagealphablending($shirtimagepreview, false); imagesavealpha($shirtimagepreview,true); $transparent = imagecolorallocatealpha($shirtimagepreview, 255, 255, 255, 127); imagefilledrectangle($shirtimagepreview, 0, 0, 590, 520, $transparent); imagecopyresampled($shirtimagepreview, $tshirtbackgroundimage, 0, 0, 0, 0, 590, 520, 590, 520); imagealphablending($shirtimagepreview, true); //6b. Resize the original image $newimageheightpreview = 280 * ($uploadedfileheight / $uploadedfilewidth); $shirtimagepreviewfront = imagecreatetruecolor(280,$newimageheightpreview); imagealphablending($shirtimagepreviewfront, false); imagesavealpha($shirtimagepreviewfront,true); $transparent = imagecolorallocatealpha($shirtimagepreviewfront, 255, 255, 255, 127); imagefilledrectangle($shirtimagepreviewfront, 0, 0, 280, $newimageheightpreview, $transparent); imagecopyresampled($shirtimagepreviewfront, $uploadedimage, 0, 0, 0, 0, 280, $newimageheightpreview, $uploadedfilewidth, $uploadedfileheight); // 6c. copy one to the other imagecopy($shirtimagepreview,$shirtimagepreviewfront,155,105,0,0,280,$newimageheightpreview); Also, it's too late to back out of GD for this project, but does anyone have any heartfelt recommendations for another image library to use with php? Thanks!
November 17, 200916 yr Author ImageSaveAlpha: Thanks for the suggestion—am I using imagesavealpha in completely the wrong way?! I've tried every combination of true and false for imagesavealpha and imagealphablending, but anything other than what I have causes one or both of the images' backgrounds to be drawn black. The only thing I can think is that I have a complete misconception about how one of the functions works, as everything looks as it should to me! Cheers.
Create an account or sign in to comment