// header ("Content-type: image/png"); // <- use if dumping directly to screen
// Load in an image from a file. Get its height and weight
$im_kanga = imagecreatefromjpeg("kanga.jpg");
$w_kanga = imagesx($im_kanga);
$h_kanga = imagesy($im_kanga);
// Make a blank 'canvas' 1000x500 pixels in size
$im = @imagecreatetruecolor(1000, 500)
or die("Cannot Initialize new GD image stream");
// define some colors we'll have to draw with. Note we need to pass it
// a pointer to the image canvas we'll be drawing on. I'm going to guess
// this has to do with drawing on things with less than 24 bit color
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
// fill the canvas with white (by default its black)
imagefill($im, 0, 0, $white);
// copy our first image onto the other from coords 0,0 to 0,0
// copying the whole thing
imagecopy($im, $im_kanga, 0, 0, 0, 0, $w_kanga, $h_kanga);
// Stick on some text. It seems we must point to the exact file of the font
// we want to use.
$pad = 5;
imagettftext($im, 32, 0, $pad + $w_kanga, $pad + 50, $black,
// "/Library/Fonts/Arial",
"/usr/share/fonts/bitstream-vera/Vera.ttf",
"Boxaroo two!");
// write out the image. If you don't specify the filename, the output
// gets dumped to the screen (if you wanted the script to simply
// draw the image right then and there
imagejpeg($im, "/var/www/twiki/pub/PII/ConfirmationMockups/out.jpg");
// cleanup
imagedestroy($im);
--
MattWalsh - 16 May 2007
- Output from demo: