Jump to content

Archived

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

Gobiggi

Image Generation

Recommended Posts

k ive been looking for help in loads of places, and got some of it, so ive got this far but my script still doesn't work, all i get is a red X,
what i am aiming for is to create images like this:
[img]http://i111.photobucket.com/albums/n148/Gobiggi/Gobiggi.gif[/img]
but what i need is the last pixel of the last word staying in the same place for every text that is entered, so far my script is:
[code]<?php
  header("Content-type: image/png");
  $string = urldecode($_GET['text']);
  $im = imagecreatefrompng("template.png");
  $fontsize = 10;
  $fontsize2 = 12;
  $angle = 25;
  $font = "visitor1.ttf";
  $textColor = imagecolorallocate($im,255,255,255)
  $textColor2 = imagecolorallocate($im,0,0,0);
  array imagettfbbox(12,25,$font,$string);
  imagettftext($im, $fontSize2, 25, 291, -1, $textColor2, $font, $string);
  imagettftext($im, $fontSize, 25, 290, 0, $textColor, $font, $string);
  imagepng($im);
  imagedestroy($im);
?>
[/code]
but i really think ive made loads of mistakes that i cannot find,
please help me do this.

Share this post


Link to post
Share on other sites
try
[code]<?php
  header("Content-type: image/png");
  $string = urldecode($_GET['text']);
  $im = imagecreatefrompng("template.png");
  $height = imagesy($im);
  $width = imagesx($im);
  $fontsize = 10;
  $fontsize2 = 12;
  $angle = 25;
  $font = "visitor1.ttf";
  $textColor = imagecolorallocate($im,255,255,255);
  $textColor2 = imagecolorallocate($im,0,0,0);
  $array  = imagettfbbox($fontsize2,$angle,$font,$string);
  $ypos = $height - 5; // baseline of text
  $xendpos = $width-10; // text ends 10px from right
  $textwidth = $array[2] - $array[0];
  $xpos = $xendpos - $textwidth;
  imagettftext($im, $fontSize2, $angle, $xpos+1, $ypos-1, $textColor2, $font, $string);
  imagettftext($im, $fontSize, $angle, $xpos, $ypos, $textColor, $font, $string);
  imagepng($im);
  imagedestroy($im);
?> [/code]

Share this post


Link to post
Share on other sites
Wow! Thanks man,
but i still have one problem, when i type:
img.php?text=Gobiggi
no text appears

but thanks for the above text, and hopefully you can help me overcome this problem, because im a total php noob,

Share this post


Link to post
Share on other sites
c'mon nearly an hour and no replies, i really want to get this script done so i can get it out of the way

Share this post


Link to post
Share on other sites
Works better if both fontsizes are the same

[code]<?php
  header("Content-type: image/png");
  $string = urldecode($_GET['text']);
  $im = imagecreate(100, 120);  // as I don't have your template image'
  $height = imagesy($im);
  $width = imagesx($im);
  $fontsize = 12;
  $fontsize2 = 12;
  $angle = 25;
  $font = "c:/windows/fonts/arialbd.ttf";    // used a font on my pc here
  $bg = imagecolorallocate($im, 228,228,228);
  $textColor = imagecolorallocate($im,255,255,255);
  $textColor2 = imagecolorallocate($im,0,0,0);
  $array  = imagettfbbox($fontsize2,$angle,$font,$string);
  $ypos = $height - 50; // baseline of text
  $xendpos = $width-10; // text ends 10px from right
  $textwidth = $array[2] - $array[0];
  $xpos = $xendpos - $textwidth;
  imagettftext($im, $fontsize2, $angle, $xpos+1, $ypos-1, $textColor2, $font, $string);
  imagettftext($im, $fontsize, $angle, $xpos, $ypos, $textColor, $font, $string);
  imagepng($im);
  imagedestroy($im);
?>[/code]

Share this post


Link to post
Share on other sites

×

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.