Forum Moderators: coopster
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
$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
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.
$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);