Forum Moderators: coopster

Message Too Old, No Replies

Image overlay with text script?

         

havoc

3:35 am on Jul 14, 2003 (gmt 0)

10+ Year Member



Hey there,

i'm totally new to GD with PHP

I wanted to see how i would go about taking a file and adding text to it . Ultimately would i would like to do is get the image size and add a black box down the bottom with text .

Have any of your guys have a simple script i could look at to give me an idea. I have been reading PHP's webpage and slow am getting an idea on how things work

havoc

5:10 am on Jul 14, 2003 (gmt 0)

10+ Year Member



Ok i got this working but i cant the the overlay text to be white i can only get it to be very very dark grey

$imtext=ImageCreate (250,22); // Make new,
$black = ImageColorAllocate ($imtext, 0, 0, 0); // Set black point
$white = ImageColorAllocate ($imtext, 255, 255, 255); // Set white point

ImageTTFText($imtext, 8, 0, 5, 10, $white, "smallfont.ttf","TEXT GOES HERE");

An when i use imagecopymerge()
its really dark grey .. suggestions?

Also how to i output the ImageJPG() to a file i have it just display in a broswer at the moment

hakre

10:34 am on Jul 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi havoc,

maybe imageColorClosest may help, because jpeg is truecolor or grayscale:

$near_white = imageColorClosest($img, 255,255,255);

the imagejpeg [php.net] function can create a jpeg file for your needs. just put the filename as second parameter (ie images/test.jpg).

- hakre.

havoc

11:41 am on Jul 14, 2003 (gmt 0)

10+ Year Member



No that didnt work it just blacked it out .. im not sure what im doing wrong

havoc

3:43 am on Jul 15, 2003 (gmt 0)

10+ Year Member



This is the whole script maybe someone can work it out :(

$im = ImageCreateFromJPEG("images/test.jpg");
// Create a gd image ($im) first.

$size = getimagesize("images/test.jpg");
$width= "$size[0]";
$height= "$size[1]";

$imtext= ImageCreate(250,22);
$black = ImageColorAllocate ($imtext, 0, 0, 0); // Set black
$white = ImageColorAllocate($imtext, 255,255,255);

ImageTTFText($imtext, 8, 0, 5, 10, $white, "smallfont.ttf","tex text text text ");
// Make TTF text and overlay it onto the image.
// Adjust $fontpath to your actual fonts directory.

ImageCopyMerge($im, $imtext, 0, $height-15, 0,0,$width,22,33);
// Centre text within image

header("Content-type: image/jpeg");
ImageJPEG($im, /images/test.jpg);

havoc

3:01 am on Jul 16, 2003 (gmt 0)

10+ Year Member



no one ... well is there another way i can put a tag on an image?