Jump to content

Text on Image Generation


iNinja

Recommended Posts

Hey, and thanks in advance for anyone who can help me,

I was wonder how I have a text box, you type in your name and it prints in on a image

 

so lets say Ive got a template at "/template.png"

and I want to get my name on it "iNinja"

so i would like a PHP web application to have a text box, you type in iNinja and click the submit button and it saves the newly created image as "/image1.png" (if thats taken then "/image2.png" and so on...)

 

Thanks very much, Im starting out and need a place to work off.

Link to comment
Share on other sites

This is what I did to create a Dynamic Sig.  I used XML, so it may not pertain to how you are doing it, but maybe it gives you some ideas.

 

This is actuall a file named mysig.jpg (notice the extension)

 

<?php
Header ('Content-type: image/jpeg');
Header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Pragma: no-cache');


$current = "";
$pilot = '';

function start_tag($parser, $name, $attribs) {
   global $current;
   $current = $name;
}

function end_tag($parser, $name) {
global $current, $pilot;
}

function tag_contents($parser, $data) {
   global $current, $pilot;	 
   if ($current == "name") {$pilot[] = $data;}
   if ($current == "flights") {$pilot[] = $data;}
 if ($current == "miles") {$pilot[] = $data;}
   if ($current == "hours") {$pilot[] = $data;}

}

$parser = xml_parser_create();

xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
xml_set_element_handler($parser, "start_tag", "end_tag");
xml_set_character_data_handler($parser, "tag_contents");

$document = file_get_contents("pilots.xml","r") 
       or die("Error reading XML data.");

xml_parse($parser, $document);
xml_parser_free($parser);
/*
echo $pilot[0];
echo $pilot[2];
echo $pilot[4];
echo $pilot[6];	 
*/

// create the image using your own background
$image = imagecreatefromjpeg("FSESig.jpg");

// dimensions of the image used
$img_width = 440;
$img_height = 111;

// set the colours
$cool  = imagecolorallocate($image, 81, 86, 96);
$black = imagecolorallocate($image, 0, 0, 0);
$white = imagecolorallocate($image, 255, 255, 255);
$red   = imagecolorallocate($image, 255, 0, 0);
$grey  = imagecolorallocate($image, 204, 204, 204);
$green = imagecolorallocate($image, 206, 129, 18);
$blue  = imagecolorallocate($image, 0, 0, 255);

// set the font and print text
$font = '/home/users/web/b2031/pow.bdcpaging/htdocs/fsesig/arial.ttf';


// now i will create a line with font size 8, with no angle, 10 pixels to the right, and 17 pixels down
ImageTTFText ($image, 8, 0, 10, 40, $black, $font, "Pilot... $pilot[0]");
ImageTTFText ($image, 8, 0, 10, 60, $black, $font, "Flights Flown... $pilot[2]");
ImageTTFText ($image, 8, 0, 10, 80, $black, $font, "Miles Flown... $pilot[4]");
ImageTTFText ($image, 8, 0, 10, 100, $black, $font, "Hours Flown... $pilot[6]");

// output and destroy
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.