sammysmee Posted March 8, 2009 Share Posted March 8, 2009 Hi there, i currently have a perfect gd code running on my stock art site, i have it so it renders the png with a watermark across it, however due to it being a png it puts a black background behind the thumbnail and the resized image, i would like to make this white, but i do not know GD (i was given the gd code) could any one help? I tried solving it but with no luck. the code is below.. //$filename should be a JPG and $watermark a PNG-24 with alpha transparency. $quality is 1-100 JPG quality on output. function watermark($srcfilename, $newname, $watermark, $quality) { $imageInfo = getimagesize($srcfilename); $width = $imageInfo[0]; $height = $imageInfo[1]; $logoinfo = getimagesize($watermark); $logowidth = $logoinfo[0]; $logoheight = $logoinfo[1]; $horizextra =$width - $logowidth; $vertextra =$height - $logoheight; $horizmargin = round($horizextra / 2); $vertmargin = round($vertextra / 2); $photoImage = ImageCreateFromPNG($srcfilename); ImageAlphaBlending($photoImage, true); $logoImage = ImageCreateFromPNG($watermark); $logoW = ImageSX($logoImage); $logoH = ImageSY($logoImage); ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH); //ImageJPEG($photoImage); // output to browser ImageJPEG($photoImage,$newname, $quality); ImageDestroy($photoImage); ImageDestroy($logoImage); } function createthumb($name,$filename,$new_w,$new_h) { $system=explode(".",$name); if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);} if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);} if (preg_match("/gif/",$system[1])){$src_img=imagecreatefromgif($name);} if (preg_match("/bmp/",$system[1])){$src_img=imagecreatefromwbmp($name);} $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; //$thumb_h=$old_y*($new_h/$old_x); $thumb_h=$new_h; } if ($old_x < $old_y) { //$thumb_w=$old_x*($new_w/$old_y); $thumb_w=$new_w; $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if (preg_match("/png/",$system[1])) { imagepng($dst_img,$filename); } else if (preg_match("/jpg|jpeg/",$system[1])) { imagejpeg($dst_img,$filename); } else if (preg_match("/bmp/",$system[1])) { imagewbmp($dst_img,$filename); } else { imagegif($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); } Link to comment https://forums.phpfreaks.com/topic/148506-gd-png-black-background-turning-it-to-white/ Share on other sites More sharing options...
sammysmee Posted May 15, 2009 Author Share Posted May 15, 2009 sorry to bump, but its been months and i still need the help! thanks - sammy Link to comment https://forums.phpfreaks.com/topic/148506-gd-png-black-background-turning-it-to-white/#findComment-834771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.