Forum Moderators: coopster

Message Too Old, No Replies

GD Text Alignment

A Little More Descriptive

         

bluesguitarman25

9:23 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Ok, what I need to do is take a pre-existing image and specifically place text in diff areas of the image and save that as a new image. This is what I have so far...

<?php
header("Content-type: image/png");
$string = $_POST['text'];
$im = imagecreatefrompng("image.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string) / 2);
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>

My main Prob right now is aligning the text where I want it. In the end we are talking about several form variables right aligned over the image, sort of like and ID on the fly. Thanks

coopster

2:11 am on Jul 4, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like you've been working on this for a bit now! Basically, you need to calculate the box surrounding the text (often called the bounding box) and align that to the right side of your image (based on width). Here is a message from the past that may help you get started:
PHP with images [webmasterworld.com]