Some Poster55 Posted December 31, 2008 Share Posted December 31, 2008 Hi, Basically, I'm looking for some help with resizing a png image that has a transparent background. Here's what I'm currently working with: <?php $image1 = imagecreatefrompng("first_image.png"); $width = 59; $height = 112; $newwidth=70; $newheight=112; $image2=imagecreatefrompng("blank_background.png"); imagecopyresampled($image2,$image1,0,0,0,0,$newwidth,$newheight,$width,$height); imagepng($image2,"result.png",9); imagedestroy($image1); imagedestroy($image2); ?> The "first_image.png" file is the image with a transparent background which I need to resize. The "blank_background.png" is a completely transparent and blank image which I'm using to resize the first image using the imagecopyresampled() function. However, upon running the script, I end up with my original image perfectly resized - but with a white background instead of a transparent background. How can I resize the original image, but with retaining the transparent background? Help would be greatly appreciated, thanks! Link to comment https://forums.phpfreaks.com/topic/138963-php-gd-resizing-a-png-image-while-keeping-its-background-transparent/ Share on other sites More sharing options...
GingerRobot Posted December 31, 2008 Share Posted December 31, 2008 You'll need to save the alpha channel information of $image2 before you save it with imagesavealpha Link to comment https://forums.phpfreaks.com/topic/138963-php-gd-resizing-a-png-image-while-keeping-its-background-transparent/#findComment-726835 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.