I've been doing some digging for the past 4 hrs and have yet to find a work around for this. I'm trying to add text over a .png image (name and level). Using imagecreatetruecolor() creates a black background which is normal. The problem is that I'm still getting black edges around my images after making the black bg transparent. Is there a way I can avoid using imagecreatetruecolor() altogether and simply put the text over the existing .png image? I really appreciate any help you can give me!!!
My code is shown below..
Code: Select all
if($aid == $id){
// The adoptable exists, so let's try and show the image
$usingimage = "no";
$image = getcurrentimage($id);
// Let's see if the server has support for GD or not
// Also to use fancy images the image must be a gif and fancy images must be enabled...
$usegd = grabanysetting("gdimages");
$imageinfo = @getimagesize($image);
$imagemime = $imageinfo["mime"]; // Mime type of the image file, should be a .gif file...
if(function_exists('imagepng') and $usegd == "yes" and $imagemime == "image/png")
{
$usingimage = "yes"; //Turn the template system off
// BEGIN NEW CODE
list($width, $height, $type, $attr) = getimagesize($image); // The size of the original adoptable image
// Begin the fancy outputs...
// Lets create the new target image, with a size big enough for the text for the adoptable
$newheight = $height + 20;
if($newwidth < 120){
$newwidth = 120;
}
else{
$newwidth = $width;
}
$img_temp = imagecreatetruecolor($newwidth, $newheight);
$alphablending = true;
// Lets create the image and save its transparency
$img_old = @imagecreatefrompng($image);
imagealphablending($img_old, true);
imagesavealpha($img_old, true);
// Lets copy the old image into the new image with
// the given size
ImageCopyResampled(
$img_temp,
$img_old,
0, 0, 0, 0,
$width,
$height,
$width,
$height
);
$textheight = 115;
$image = $img_temp;
$bgi = imagecreatetruecolor($newwidth, $newheight);
$color = imagecolorallocate($bgi, 51, 51, 51);
$str1 = "".$name;
$str2 = "lvl: ".$totalclicks;
$text_width = imagefontwidth(2)*strlen($str1);
$x = 60 - (ceil($text_width/2));
$text_width = imagefontwidth(2)*strlen($str2);
$x2 = 60 - (ceil($text_width/2));
imagestring ($image, 2, $x, $textheight, $str1, $color);
imagestring ($image, 2, $x2, $textheight + 13, $str2, $color);
$background = imagecolorallocate($image, 0, 0, 0);
ImageColorTransparent($image, $background);
header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
imagedestroy($img_temp);
imagedestroy($img_old);
imagedestroy($bgi);
}
else{