...

View Full Version : GD Question



SDP2006
12-23-2003, 09:55 PM
<?php
$img_handle = ImageCreate (339, 60) or die ("Cannot Create image");
$bg = "tc.png";
$txt_color = ImageColorAllocate ($img_handle, 23, 124, 0);
ImageString ($img_handle, 31, 5, 5, "Coming Soon....", $txt_color);
header ("Content-type: image/png");
ImagePng ($img_handle);
?>
My question is. What I am trying to do is I have an image, tc.png, and I want to put text on top of tc.png. It just shows up 339x60 image with a green background. Can someone help?

Thanks

stuntboy
12-24-2003, 03:49 AM
You will need to allocate at least one more colour. Right now you are creating an image with just one colour, So the background is the only colour it can be the same as the text.

<?php

$img_handle = ImageCreate (339, 60) or die ("Cannot Create image");

$bg = "tc.png";
$another_color= ImageColorAllocate ($img_handle, 255, 255, 255);
$txt_color = ImageColorAllocate ($img_handle, 23, 124, 0);

ImageString ($img_handle, 1, 5, 5, "Coming Soon....", $txt_color);

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

ImagePng ($img_handle);

?>

That will work.. though I am not sure what font 31 is, 31 does not refer to fontsize but one of the inbuilt fonts which is a number from 1 to 5. For better fonts I recommend true type fonts.

stuntboy
12-24-2003, 03:52 AM
Oh I just read the rest of your question. you do not need to create another colour since you are creating an image from an existing png. but you need to use imagecreatefrompng()



<?php

$img_handle = imagecreatefrompng("tc.png"); or die ("Cannot Create image");

$txt_color = ImageColorAllocate ($img_handle, 23, 124, 0);

ImageString ($img_handle, 1, 5, 5, "Coming Soon....", $txt_color);

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

ImagePng ($img_handle);

?>

That should work :)

SDP2006
12-24-2003, 02:31 PM
Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum