Jump to content

[SOLVED] How To Create Multiple Text Boxes on Image?


inferium

Recommended Posts

I've made a script based on a tutorial, and I have the basice function working. It's just a basic script to put text over an image from my server.

 

My question is this: how can I put multiple strings of text positioned across the image?

 

 

<?php
$image = ImageCreateFromPNG("image.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'arial.ttf';
$fontSize = "12";
$fontRotation = "0";
$str = "Example of GD in PHP.    Date: " . date("m-j-Y  g:i:s (a)");

/* Shadow */
ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str);

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str);

header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
?>

Just call the function multiple times, but change the position:

<?php
$image = ImageCreateFromPNG("image.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'arial.ttf';
$fontSize = "12";
$fontRotation = "0";
$str = "Example of GD in PHP.    Date: " . date("m-j-Y  g:i:s (a)");

/* Shadow */
ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str);

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str);

$str = "Some more text";

/* Shadow */
ImageTTFText($image, $fontSize, $fontRotation, 7, 52, $colorShadow, $font, $str);

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 5, 50, $color, $font, $str);

header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.