Nov 22, 2009
Pages: 1, 2

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

free web hosting

Read Latest Entries..: (Post #12) by iGuest on Feb 8 2008, 11:35 PM.
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
Read the FIRST post of this Topic. - Express your Opinion! Contribute Knowledge :-).

Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

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

BuffaloHELP
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 Trap17'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
CODE
<?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
CODE
WINNER - USERNAME

For a working demo please refer to #23, #24 and #25 here http://www.trap17.com/forums/index.php?s=&...ndpost&p=222107

Let's break it down. As you can see in Code 1
CODE
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.

CODE
$image = imagecreatefrompng("../images/sotw_background.png");
states the location of the background image you are going to use. It looks like this IPB Image

CODE
//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.

CODE
$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
CODE
$string = "your text 1";
$string = "your text 2";
etc. You can even do a random text where
CODE
$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";


CODE
//($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
CODE
[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.

 

 

 


Comment/Reply (w/o sign-up)

Johnny
Great stuff Buffalo, and thanks for the help. smile.gif

Comment/Reply (w/o sign-up)

nehmanator333
Yeah, it's very useful.

Comment/Reply (w/o sign-up)

electron
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:
www.esigs.be

My sig is also using that.

Comment/Reply (w/o sign-up)

peroim
this is a great code, i've been looking for something like this everywere. tyvm

Comment/Reply (w/o sign-up)

farsiscript
thanks dear BuffaloHELP
i 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

Comment/Reply (w/o sign-up)

Regain
cool THX ^^

Comment/Reply (w/o sign-up)

sendot
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.

Comment/Reply (w/o sign-up)

Imtay22
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!

Comment/Reply (w/o sign-up)

joacorock
It's very a nice code, and useful!

Comment/Reply (w/o sign-up)

Latest Entries

iGuest
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

Comment/Reply (w/o sign-up)

galexcd
QUOTE(FeedBacker @ Jan 26 2008, 11:45 AM) *
Is there a way to change the font face??


If you use imagettftext() instead of imagestring() you can specify a certain true type font on your server.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Pages: 1, 2
Similar Topics

Keywords : dynamic, image, signature, generator, simple, code, change, text, image

  1. Php Form Generator Class
    (2)
  2. Php - Fetching Random Line From A Text File
    and displaying it using AJAX/iframe (0)
    What you should know: HTML, PHP basics (executing php scripts) Examples: Using AJAX Using
    iframe Download Examples Using this script you can display a random quote/fact every time a
    visitor clicks the link. It happens dynamically without reloading the whole page. Useful for keeping
    a site fresh and lively. For example, you can have it in "About Me" page of a website which is
    rarely updated. All the quotes are stored in a text file separated by a line break. Although I have
    included a sample collection, you are free to modify or create your own. Thanks to Davi....
  3. Php Code For Login Form With Validation In Php
    (7)
    I dont want to use javascript as a validation form i want to use Regular expression in PHP for Login
    or other page. please any one have a best code for validation in PHP. as i thinks that web site
    Validation on server site is faster then client site validation. Most welcome.....
  4. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ....
  5. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  6. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free host
    together so am writing some posts. Here's a little summin' summin' about malicious code
    injection with PHP applications. Basically, this security exploit is one of the oldest tricks in
    the books and all comes down to the fact that PHP allows execution of both local and remote scripts
    with the SAME function... dur. Anyway, this is how it works. Image you've just employed a young
    go getter, straight outta uni, who has found becoming a Jack of all trades a sinch. Y....
  7. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  8. Image Upload
    ?!? (11)
    I need the image upload script which automatically resized the image by specified size and store it
    in the specified folder.....
  9. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  10. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  11. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  12. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  13. Use Rss In Php Code
    (3)
    so, how can I make RSS reader on my website? thanks in advance....
  14. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE $p = $_GET ; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.' ) == False ) { // pages
    = directory where you store your pages    $file = './' . $p . '.php'; } else { //
    1.php =  defult page    $file = './index.php'; } include $file; ?> ....
  15. I Need Some Proof Reading For My Code Please! [resolved]
    (7)
    Well... everything is fine except the Content Select section (refer to the in-code headings)...
    thats where it says the error is... could anyone find out why it wont work when I click one of my
    links? http://2kart.trap17.com/progress.php for an example of what happens...
    //----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay =
    "/images"; //------------------ //navigation //------------------ $link = ·   Home html; $link
    = ·   Portfolio html; $link = ·   Programming html; $link = ·   Graphics html; $link
    = ....
  16. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  17. Getting An Array Value Of A Dynamic Variable
    (9)
    Ok i can't believe I need help in php but I can't figure this out... If i have an array,
    lets say called test, how do i get a certain value from that array when referencing it dynamically
    by either a string or another variable? Example: CODE $test=array(1,2,5); $name="test";
    //Doesn't work: echo $$name ; /Doesn't work: echo ${$name} ; ....
  18. Php And Flash Image Gallery
    Need some help in creating or editing an xml file while viewing some o (5)
    Hello there and thanks for the helping hand you are offering. PHP newbie here! /ph34r.gif"
    style="vertical-align:middle" emoid=":ph34r:" border="0" alt="ph34r.gif" /> So here is my problem:
    On my website I have a flash image gallery.The way the gallery works is by uploading pictures in a
    folder and editing? an xml file.(pics.xml) where it adds the following code when you upload a
    picture: CODE           etc... Now I have users that upload products they sell on the
    website or they advertise their business(hotels, jewellers, car resellers,...) So for eve....
  19. Can I Make Dynamic Menu In Php
    is it posible to make dynamic menu in php without javascript (7)
    As there are many java script by which we can have event based interaction like,message on mouse
    over etc,that we can create dynamic menu in javascripts to make navigation bar ,but is it possible
    in php to have this acomplished without javascripts,i am new to php,is it possible?. Thanks....
  20. Display The Current Date/time
    With a simple PHP code (4)
    Use this code to display the current date and time. CODE   $date = date('l dS \of F Y
    h:i:s A');   echo "$date"; ?> "l" would display the current day of the week such as
    Sunday. d displays the day of the month... such as 1 and S adds the appropriate suffix(st). /of
    simply displays the word "of". F displays the current month with no abbreviations while Y displays
    the four digit year(2007). "h" displays the current hour with leading zeros if necessary(Ex. 06 for
    6 o'clock). "i" displays the minute of the hour with leading zeros if necessary. ....
  21. Dynamic Php Pages
    Nice tutorial (5)
    This is a really good tutorial on making php pages that normally appear as
    www.domainname.com/links.php appear as www.domainname.com/index.php?page=links
    http://nuwen.com/tutorials/php-dynamic-pages ....
  22. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE header("Content-Type: text/vnd.wap.wml"); echo '
    ';   print " "; if ($url == "") {      echo " Enter url: »View source code ";   }
    if ($url == "$url") {    $udata=@file_get_contents("$url"); $udata = str_replace("$","$$",$udata);
    $udata = str_replace("&","&",$udata); $udata = str_replace("'","'",$udata); $udata =
    str_replace(" $udata = str_replace(">",">",$udata); $udata = str_replace("\"....
  23. Watermark Your Image With Simple Php Script
    found it on the net (39)
    This script was found on the net http://tips-scripts.com/?tip=watermark#tip B&T's Tips &
    Scripts site. Just in case the site may not show, I will include the code here: List of things
    needed: 1. your image in any format 2. watermark image--in gif format with transparent background 3.
    script below with name (i.e. watermark.php) CODE // this script creates a watermarked image
    from an image file - can be a .jpg .gif or .png file // where watermark.gif is a mostly transparent
    gif image with the watermark - goes in the same directory as this script // where this....
  24. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  25. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved to
    Programming. ....
  26. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  27. Get Filename Of Referring Url
    php code to get filename of referring URL (9)
    Hey /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> I want to know how
    to get the filename of the referring URL. Look at the following example: Page A which has a URL of
    http://blah.trap17.com/blah/blah1.php redirects the user to Page B which has a URL of
    http://blah.trap17.com/blah/blah2.php . Is there a PHP code that I can put on blah2.php that will
    output blah1.php? I tried _SERVER ; (please note the code may not exactly be correct as I do not
    remember the code /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' />....
  28. Php Clock
    source Code (8)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE // Binary Clock // script
    copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    http://www.psychodad.at/clock/ // free to use, copy and modify but leave comments untouched;) //
    just include this file where your binary clock should appear // version 1.2   03 September 2003 //
    below you can change different settings // and remember to drink m000re milk! $size =  "40";  ....
  29. Random Message Generator
    (8)
    Here comes another one of Inspired's "amazing" PHP scripts. This little script lets you display
    a random message every time the user visits that particular page. It's not really that useful,
    but it does make the page a bit more "dynamic". CODE $randMsg = array("Hi, welcome to my
    page!", "Hey you! Thanks for visiting!", "Bonjour, mon ami!", "So, do you like the site?", "Come
    one, come all!"); $MsgNum = count($randMsg); $MsgGenNum = floor(rand(MsgNum)); echo $randMsg ;
    You can edit those values in the array if you want. Add more if you so choose. Enj....
  30. How do you test your php code
    (97)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for dynamic, image, signature, generator, simple, code, change, text, image

Searching Video's for dynamic, image, signature, generator, simple, code, change, text, image
See Also,
advertisement


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

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com