<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
header("Content-type: image/png");
if ($_SESSION["message"]){
$message = $_SESSION["message"];
}else{
$message = $_GET['message'];}
$im = imagecreatefrompng("Heart1.png");
$message_bbox = imagettfbbox(10, 0, "visitor.ttf", $message);
$imgx = (imagesx($im) - 5.5 * strlen($message)) / 2;
$imgy = (imagesy($im)/1.5) ;
$color = imagecolorallocate($im, 255, 255, 255);
$outline = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 10, 0, $imgx, $imgy, $color, "visitor.ttf", $message);
imagepng($im);
imagedestroy($im);
?>
Simple image script
Started by Max-Evans, Mar 07 2008 06:56 PM
8 replies to this topic
#1
Posted 07 March 2008 - 06:56 PM
Okay, so I've been searching for a good site that has people who know php scripting to help. I've been through maybe 4 sites that nobody on the site knew how to help. But after looking through this site, and tutorials and stuff. I'm confident that I found a site that might actually be able to help me. So I have this GD script I've been using for a while. I'm working on a userbar generator. I'm a beginner with this stuff, but I'm trying to learn more about it. So with this.. first I want to work on the text. I have it the way I want, and I'll show the code. What I want, is a 1 px outline around the text, I've tried a few things and couldn't figure it out. I've tried asking some people who knew php on other sites, and still nothing. Anyone here know how to? I've looked in alot of places for references and couldn't find anything to help, and I've seen other generator scripts with it, so I know it's possible. Anyway, here's the script.. I even have the color for the text outline
|
|
|
#2
Posted 07 March 2008 - 07:40 PM
hm... I'm not sure, but I may be able to come up with a solution. That will be my project for the night. :)
#3
Posted 07 March 2008 - 09:35 PM
Thanks! I've tried with as much as I know, and I couldn't figure it out. But then again, I don't know very much. I hope to soon be able to learn more to be able to write advanced scripts. But thanks again for helping!
#4
Posted 07 March 2008 - 11:27 PM
Here you go! Let me know if there are any bugs :)
/** * Writes the given text with a border into the image using TrueType fonts. * @author John Ciacia < John@extreme-hq.com > * @param image An image resource. * @param size The font size. * @param angle The angle in degrees to rotate the text. * @param x Upper left corner of the text. * @param y Lower left corner of the text. * @param textcolor This is the color of the main text. * @param strokecolor This is the color of the text border. * @param fontfile The path to the TrueType font you wish to use. * @param text The text string in UTF-8 encoding. * @param px Number of pixels the text border will be. * @return Returns an array with 8 elements representing four points making the bounding * box of the text. The order of the points is lower left, lower right, upper right, * upper left. The points are relative to the text regardless of the angle, so * "upper left" means in the top left-hand corner when you see the text horizontally. * @see http://us.php.net/ma...magettftext.php * @see http://forum.codecall.net * @see http://www.extreme-hq.com */ function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) { for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++) for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++) $bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text); return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text); }
#5
Posted 08 March 2008 - 12:54 AM
I'll probably feel stupid. I replaced the $fontfile with the "visitor.ttf" as in the rest of the script.. and it gives me this error.
"Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in C:\Domains\maximum-voltage.com\wwwroot\test\Heart\White\Heart1.php on line 20"
I must be doing something wrong.. haha
"Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting '&' or T_VARIABLE in C:\Domains\maximum-voltage.com\wwwroot\test\Heart\White\Heart1.php on line 20"
I must be doing something wrong.. haha
#6
Posted 08 March 2008 - 11:33 AM
$img = imagecreatefrompng("/home/john/Desktop/test.png");
$font_color = imagecolorallocate($img, 0, 0, 0);
$stroke_color = imagecolorallocate($img, 255, 0, 0);
$font = "/home/john/Desktop/ABSTRACT.TTF";
$txt = "This is a test..";
$px = 2;
imagettfstroketext($img, 10, 0, 10, 50, $font_color, $stroke_color, $font, $txt, $px);
That works for me.
#7
Posted 08 March 2008 - 04:21 PM
Okay, here's what I got. What am I doing wrong in here?
Maybe one day I'll figure it out. =P lol
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
header("Content-type: image/png");
if ($_SESSION["message"]){
$message = $_SESSION["message"];
}else{
$message = $_GET['message'];}
$im = imagecreatefrompng("Heart1.png");
$message_bbox = imagettfbbox(10, 0, "visitor.ttf", $message);
$imgx = (imagesx($im) - 5.5 * strlen($message)) / 2;
$imgy = (imagesy($im)/1.5) ;
$textcolor = imagecolorallocate($im, 255, 255, 255);
$strokecolor = imagecolorallocate($im, 0, 0, 0);
imagettftext($im, 10, 0, $imgx, $imgy, $textcolor, "visitor.ttf", $message);
function imagettfstroketext(&$im, 10, 0, $imgx, $imgy, &$textcolor, &$strokecolor, "visitor.ttf", $message, $px) {
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
$bg = imagettftext($im, 10, 0, $c1, $c2, $strokecolor, "visitor.ttf", $message);
return imagettftext($im, 10, 0, $imgx, $imgy, $textcolor, "visitor.ttf", $message);
}
imagepng($im);
imagedestroy($im);
?>
Maybe one day I'll figure it out. =P lol
#8
Posted 08 March 2008 - 05:43 PM
Do you know how to use functions?...
<?php
error_reporting(E_ALL ^ E_NOTICE);
session_start();
header("Content-type: image/png");
function imagettfstroketext(&$image, $size, $angle, $x, $y, &$textcolor, &$strokecolor, $fontfile, $text, $px) {
for($c1 = ($x-abs($px)); $c1 <= ($x+abs($px)); $c1++)
for($c2 = ($y-abs($px)); $c2 <= ($y+abs($px)); $c2++)
$bg = imagettftext($image, $size, $angle, $c1, $c2, $strokecolor, $fontfile, $text);
return imagettftext($image, $size, $angle, $x, $y, $textcolor, $fontfile, $text);
}
if ($_SESSION["message"]) {
$message = $_SESSION["message"];
} else {
$message = $_GET['message'];
}
$im = imagecreatefrompng("Heart1.png");
$message_bbox = imagettfbbox(10, 0, "visitor.ttf", $message);
$imgx = (imagesx($im) - 5.5 * strlen($message)) / 2;
$imgy = (imagesy($im)/1.5) ;
$textcolor = imagecolorallocate($im, 255, 255, 255);
$strokecolor = imagecolorallocate($im, 0, 0, 0);
imagettfstroketext($im, 10, 0, $imgx, $imgy, $textcolor, $strokecolor, "visitor.ttf", $message, 1);
imagepng($im);
imagedestroy($im);
?>
#9
Posted 08 March 2008 - 05:50 PM
Ahh okay.. sorry, my brain is kind of fuzzed lately. I'm not too advanced.. but I haven't been able to think straight lately.. But I'm learning.. slowly.. So I had it in the wrong place.. figures it would be something stupid on my part. Haha.. thanks though. Works great!


Sign In
Create Account

Back to top









