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);
?>

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.