sheraz Posted August 19, 2010 Share Posted August 19, 2010 hi, i am trying to generate image gallery. but the problem is that when i upload the png files its thumbnail is generated with black background. JPEG an GIF thumbnail are generated successfully. i want to make background transparent. is there any solution that how i can get rid of it. i am using imagecreatetruecolor($thumbwidth, $thumbheight ); to generate thumbnail Link to comment https://forums.phpfreaks.com/topic/211142-how-to-change-black-background-of-thumbnail/ Share on other sites More sharing options...
MadTechie Posted August 19, 2010 Share Posted August 19, 2010 $black = imagecolorallocate($im, 0, 0, 0); imagecolortransparent($im, $black); Resize example <?php function setTransparency($new_image,$image_source){ $transparencyIndex = imagecolortransparent($image_source); $transparencyColor = array('red' => 255, 'green' => 255, 'blue' => 255); if ($transparencyIndex >= 0) { $transparencyColor = imagecolorsforindex($image_source, $transparencyIndex); } $transparencyIndex = imagecolorallocate($new_image, $transparencyColor['red'], $transparencyColor['green'], $transparencyColor['blue']); imagefill($new_image, 0, 0, $transparencyIndex); imagecolortransparent($new_image, $transparencyIndex); } ?> Sample Usage: (resizing) <?php $image_source = imagecreatefrompng('test.png'); $new_image = imagecreatetruecolor($width, $height); setTransparency($new_image,$image_source); imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); Link to comment https://forums.phpfreaks.com/topic/211142-how-to-change-black-background-of-thumbnail/#findComment-1101139 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.