Jump to content
xisto Community
BuffaloHelp

Dynamic Image / Signature Generator a simple code to change text on an image

Recommended Posts

In search of dynamically changing quote, saying or all other types of text on an image I came across a code that I have modified to fit my initial usage. This procedure requires two files and short knowledge of PHP. If you are familiar with Xisto's sig rotation code you will understand this procedure very fast.

Code 1: dynamic_sig.php (you can rename this to index.php and you'll see at the end why)

Code 2: a simple text file named anything (I will call it name.txt)

Code 1

<?php header("Content-type: image/png"); $image = imagecreatefrompng("../images/sotw_background.png");//imagecolorallocate($image, R, G, B) in HEX values$font_black = imagecolorallocate($image, 2, 1, 8);$font_blue = imagecolorallocate($image, 25, 0, 255);$List = "name.txt";$string = trim(file_get_contents($List));;//($image, fontsize, rightindent, downindent, data, txtcolour)imagestring($image, 3, 12, 3, "T17", $font_blue);imagestring($image, 1, 86, 6, "SOTW", $font_black);imagestring($image, 1, 110, 6, $string, $font_black);  imagepng($image); imagedestroy($image); ?>
Code 2

WINNER - USERNAME
For a working demo please refer to #23, #24 and #25 here http://forums.xisto.com/topic/27020-sig-of-the-week-winners-past-winners-of-trap17com-sotw/

 

Let's break it down. As you can see in Code 1

header("Content-type: image/png");
that HEADER calls for PNG as image type. This is crucial since only PNG images can handle dynamically applied text.

 

$image = imagecreatefrompng("../images/sotw_background.png");
states the location of the background image you are going to use. It looks like this http://forums.xisto.com/topic/125-user-contributions/

 

//imagecolorallocate($image, R, G, B) in HEX values$font_black = imagecolorallocate($image, 2, 1, 8);$font_blue = imagecolorallocate($image, 25, 0, 255);
as the remark that I made, the value of color in HEX will determine the text color you choose. I made two to make it as a comparison.

 

$List = "name.txt";$string = trim(file_get_contents($List));;
This assigns a SINGLE line characters from file named name.txt. And then assigns to variable name STRING from the opened text file. If you don't want to use external file, you can simply set

$string = "your text 1";$string = "your text 2";
etc. You can even do a random text where

$select = rand(1,7);if($select==1)$string = "text 1";if($select==2)$string = "text 2";if($select==3)$string = "text 3";if($select==4)$string = "text 4";if($select==5)$string = "text 5";if($select==6)$string = "text 6";if($select==7)$string = "text 7";

//($image, fontsize, rightindent, downindent, data, txtcolour)imagestring($image, 3, 12, 3, "T17", $font_blue);imagestring($image, 1, 86, 6, "SOTW", $font_black);imagestring($image, 1, 110, 6, $string, $font_black);
This is where the magic happens. As you can see the position of the text is determined by second two numbers. The first number determines the font size. Instead of preset characters, i.e. T17 and SOTW, you can have $string1, $string2 etc.

 

The rest is needed to close up the PNG image and safely project reconstructed new image onto the browser.

 

About the sig rotator reference: By renaming dynamic_sig.php to index.php and placing it under a directory called filename.png (yes directory with extension), you can use your newly created dynamic image in the forum

[img]http://source_site/filename.png[/img]
This will display the dynamic image as though it's been there all along.

 

One key note is that text is only written within the boundary of an image. So if you are looking for larger image simply make your picture larger in dimension. You can have multiple rows and variable font sizes.

Share this post


Link to post
Share on other sites

Hay i have a site dedicated towards this thing.I made this sig generator and people can use it as well.Just register fill in the text and you are done.here is the link:http://forums.xisto.com/no_longer_exists/
My sig is also using that.

Share this post


Link to post
Share on other sites

thanks dear BuffaloHELPi want write sig maker ( random text , visit ip address and more ) how can i do that ?This is my questions for example do you have GD image soruce or tutorials ?i must user GD image ?thanks

Share this post


Link to post
Share on other sites

Great script, but for some reason when I upload it to my ftp and link it to forums it shows up as the dreaded red x. Do you have any ideas why this may be? I can send you my edited PHP file and everything if you need, I just really wanna get this thing working.EDIT: I apologize, but I already fixed the problem. Thanks again for the script.

Edited by sendot (see edit history)

Share this post


Link to post
Share on other sites

Wow, I was looking all over for a code like this one! I downloaded one once, but it included over 100 php files. which would take 2 hours to download and upload. Now I found a code that has two files and takes up little space!

Share this post


Link to post
Share on other sites

adding images to images

Dynamic Image / Signature Generator

 

How would you add an image on top of $image in a specific location?

 

-question by halo2pac

Share this post


Link to post
Share on other sites
battlefield heroes dynamic signature codeDynamic Image / Signature Generator

<?php Header("Content-type: image/png"); $image = imagecreatefrompng("../images/sotw_background.Png");//imagecolorallocate($image, R, G, B) in HEX values$font_black = imagecolorallocate($image, 2, 1, 8);$font_blue = imagecolorallocate($image, 25, 0, 255);$List = "name.Txt";$string = trim(file_get_contents($List));;//($image, fontsize, rightindent, downindent, data, txtcolour)Imagestring($image, 3, 12, 3, "T17", $font_blue);Imagestring($image, 1, 86, 6, "SOTW", $font_black);Imagestring($image, 1, 110, 6, $string, $font_black); imagepng($image); Imagedestroy($image); ?>

Share this post


Link to post
Share on other sites
How can I make this work on my host?Dynamic Image / Signature Generator

hey everybody,

 I could use a helping hand...On my windows testing server (WAMP) I'm able to get my font working.(The reason why I made 9 text pieces is because the black ones create a border)Well, on my windows server I've used visitor1.Ttf and because my host runs on a differen OS theFont file is now a VISITORS.FON.

What happens is that it puts a username on the bg image with a black border.But on my host it just doens't work. The font wont show up...

Can anybody help me?

<?phpif (isset($_POST['submit'])){header("Content-type: image/png");$image = imagecreatefrompng("barbg.Png");//imagecolorallocate($image, R, G, B) in HEX values$font_black = imagecolorallocate($image, 2, 1, 8);$font_blue = imagecolorallocate($image, 25, 0, 255);$font_white = imagecolorallocate($image, 255, 255, 255);$string = $_POST['username'];$filename = $_POST['username'].'png';//($image, fontsize, rightindent, downindent, data, txtcolour)Imagettftext($image, 40, 0, 24, 12, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 25, 12, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 26, 12, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 26, 13, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 26, 14, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 25, 14, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 24, 14, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 24, 13, $font_black, 'VISITOR.FON', $string);Imagettftext($image, 40, 0, 25, 13, $font_white, 'VISITOR.FON', $string);imagepng($image, $filename);Imagepng($image);Imagedestroy($image);} else {?><form method='post' action="picgener.Php" name="generator">Username:<input type='text' name='username'><input type="submit" value="Make image!" name="submit" ></form><?php}?>
-reply by Floris

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.