Jump to content

PHP GD Image - Transparent image has odd background


JasonO

Recommended Posts

Hi there

 

I have created an image and so far placed text on it using GD for PHP.

 

I now want to add an image on top of the current image. I've done that however the transparency has got a white and green background. I've tried the top methods in Google to removing background to transparent image and they never worked.

 

Image:

img.php

http://www.gol-clan.net/members/sig/img.php

 

Source:

<?php
$watermark = imagecreatefrompng('http://i195.photobucket.com/albums/z136/Hexophenia/SGT-Templatecopy.png');

$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);

$img_handle = imagecreatetruecolor($watermark_width, $watermark_height);
$img_src = 'http://www.gol-clan.net/members/sig/img/sigbg1.png';
$img_handle = imagecreatefrompng($img_src);
$color = imagecolorallocate ($img_handle, 255, 255, 255);

$size = getimagesize($img_src); 

// Get the name in the URL to put in the image
$name = $_GET['name'];
//Show Text on the image
imagestring ($img_handle, 45, 15, 5, "-{GOL}-$name", $color);
imagestring ($img_handle, 20, 10, 100, "Medals & Ribbons", $color);
imagestring ($img_handle, 20, 400, 5, "Sergeant", $color);

$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 25;
imagecopymerge($img_handle, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 

// Done Image 
header ("Content-type: image/png");

imagepng ($img_handle);
imagedestroy($watermark);  
imagedestroy($img_handle);
?>

 

Sorry that's its somewhat all over the place. I've commeted what I know, unfortunatly a lot of it I don't know.

 

As you can see, the image has a funny background - however that background is a transparent one when loaded in browser directly.

SGT-Templatecopy.png

http://i195.photobucket.com/albums/z136/Hexophenia/SGT-Templatecopy.png

 

I'm stuck for ideas, so any help or points in the right direction would be helpful.

 

Thanks a lot,

Jason

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.