Jump to content
xisto Community
Sign in to follow this  
signatureimage

Forum Signature-image With Php Use PHP to create an image in real-time

Recommended Posts

With interest I have read these Topics.

What I want to do with PHP is the following:
Signatue-image

This is the Forum Signature of my cousin,
who lives in Europe.

The image is generated in real-time.
(Refresh the page, and see for yourself)

My cousin refuses to tell me how he did this.
But I want to do the same thing, also with PHP.

Any ideas?

Greetings,
John.


Notice from microscopic^earthling:
This is NOT a tutorial and in future you should be more careful about where you're posting your threads. Moved to Programming > Scripting.

Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

It's quite easy to do this actually. All you've to do is to get PHP to read your IP & whatever other Browser Stats you want and create a JPEG/GIF/PNG image dynamically and send it back to your browser. Here's a simple code that will display your IP address as an image.

<?php$img_number = imagecreate(275,25);$backcolor = imagecolorallocate($img_number,102,102,153);$textcolor = imagecolorallocate($img_number,255,255,255);imagefill($img_number,0,0,$backcolor);$number = " Your IP is $_SERVER[REMOTE_ADDR]";Imagestring($img_number,10,5,5,$number,$textcolor);header("Content-type: image/jpeg");imagejpeg($img_number);?>

You simply need to add on whatever other stats and graphics you wish to include. Modify this code and save it as a .php file and you'll get the desired results.

If you want to see the sample output of this code, visit: http://forums.xisto.com/no_longer_exists/

Share this post


Link to post
Share on other sites

How I programmed my dynamic Forum Signature Image with PHP:
(See the Signature Image at the bottom of this post)




Part [1] Prepare the texts:

Job [1.1] Find the TCP/IP address of the surfer:

[tab][/tab]$SurferAddress = $_SERVER['REMOTE_ADDR'];

Job [1.2] Find the name of the Internet Provider of the surfer:

Job [1.2] Step [1.2.1] Find the name of the machine of the surfer:

[tab][/tab]$SurferHostName = gethostbyaddr($_SERVER['REMOTE_ADDR']);

Job [1.2] Step [1.2.2] Fetch the two last qualifiers (three if United Kingdom)

[tab][/tab]$x1 = strrpos($SurferHostName,'.');  // Find the LAST . in the host-name:[tab][/tab]$Last = substr($SurferHostName,1+$x1);  // Take the LAST word:[tab][/tab]$Rest = substr($SurferHostName,0,$x1);  // Take previous part:[tab][/tab]$x2 = strrpos($Rest,'.'); [tab][/tab] // Find the NEXT-TO-LAST . in the host-name:[tab][/tab]$NextToLast = substr($Rest,1+$x2);  // Take the NEXT-TO-LAST word:[tab][/tab]$Rest = substr($Rest,0,$x2); [tab][/tab] // Take previous part:[tab][/tab]$x3 = strrpos($Rest,'.'); [tab][/tab] // Take the NEXT-TO-NEXT-TO-LAST . in the host-name:[tab][/tab]$NextToNextToLast = substr($Rest,1+$x3);[tab][/tab]// Take the NEXT-TO-NEXT-TO-LAST word:[tab][/tab]$Rest = substr($Rest,0,$x3); [tab][/tab] // Take previous part:[tab][/tab]if ($Last == 'uk')   { [tab][/tab] $SurferProvider = "$NextToNextToLast.$NextToLast.$Last";  }[tab][/tab]else  { [tab][/tab] $SurferProvider = "$NextToLast.$Last";  }

Job [1.3] Find the name of the browser:

[tab][/tab]$BrowserInfo = $_SERVER['HTTP_USER_AGENT'];[tab][/tab]if     (ereg("MSIE", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Internet Explorer";  }[tab][/tab]elseif (ereg("Firefox", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Firefox";  }[tab][/tab]elseif (ereg("Lynx", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Lynx";  }[tab][/tab]elseif (ereg("Opera", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Opera";  }[tab][/tab]elseif (ereg("WebTV", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "WebTV";  }[tab][/tab]elseif (ereg("Konqueror", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Konqueror";  }[tab][/tab]elseif (ereg("Epiphany", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Epiphany";  }[tab][/tab]elseif (ereg("Gecko", $BrowserInfo))   { [tab][/tab] $SurferBrowser = "Mozilla";  }[tab][/tab]elseif ( (eregi("bot", $BrowserInfo)) || (ereg("Google", $BrowserInfo)) || (ereg("Slurp", $BrowserInfo))   || (ereg("Scooter", $BrowserInfo)) || (eregi("Spider", $BrowserInfo)) || (eregi("Infoseek", $BrowserInfo)) )   { [tab][/tab] $SurferBrowser = "Bot";  }[tab][/tab]elseif ( (ereg("Nav", $BrowserInfo))  || (ereg("Gold", $BrowserInfo))   || (ereg("Mozilla", $BrowserInfo)) || (ereg("Netscape", $BrowserInfo)) )  { [tab][/tab] $SurferBrowser = "Netscape";  }[tab][/tab]else   { [tab][/tab] $SurferBrowser = "a browser";  }

Job [1.4] Find the name of the operating systeem:

[tab][/tab]if     (ereg("Win98", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows 98";  }[tab][/tab]elseif (ereg("Windows 98", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows 98";  }[tab][/tab]elseif (ereg("Windows NT 5.1", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows XP";  }[tab][/tab]elseif (ereg("Windows NT 5.0", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows 2000";  }[tab][/tab]elseif (ereg("Windows NT", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows NT";  }[tab][/tab]elseif (ereg("Win", $BrowserInfo))   { [tab][/tab] $SurferOs = "Windows";  }[tab][/tab]elseif ( (ereg("Mac", $BrowserInfo)) || (ereg("PPC", $BrowserInfo)) )   { [tab][/tab] $SurferOs = "Macintosh";  }[tab][/tab]elseif (ereg("Linux", $BrowserInfo))   { [tab][/tab] $SurferOs = "Linux";  }[tab][/tab]elseif (ereg("FreeBSD", $BrowserInfo))   { [tab][/tab] $SurferOs = "FreeBSD";  }[tab][/tab]elseif (ereg("SunOS", $BrowserInfo))   { [tab][/tab] $SurferOs = "SunOS";  }[tab][/tab]elseif (ereg("IRIX", $BrowserInfo))  { [tab][/tab] $SurferOs = "IRIX";  }[tab][/tab]elseif (ereg("BeOS", $BrowserInfo))   { [tab][/tab] $SurferOs = "BeOS";  }[tab][/tab]elseif (ereg("OS/2", $BrowserInfo))  { [tab][/tab] $SurferOs = "OS/2";  }[tab][/tab]elseif (ereg("AIX", $BrowserInfo))   { [tab][/tab] $SurferOs = "AIX";  }[tab][/tab]else   { [tab][/tab] $SurferOs = "a cool machine";  }

Job [1.5] Find a cool message; always different:
TODO: in MySQL

[tab][/tab]$Text_Element[1]  = "NO Software Patents !";[tab][/tab]$Text_Element[2]  = "More games !";[tab][/tab]$Text_Element[3]  = "Perl rulez !";[tab][/tab]$Text_Element[4]  = "Rexx rulez !";[tab][/tab]$Text_Element[5]  = "ADA rulez !";[tab][/tab]$Text_Element[6]  = "Python rulez !";[tab][/tab]$Text_Element[7]  = "C++ rulez !";[tab][/tab]$Text_Element[8]  = "Basic rulez !";[tab][/tab]$Text_Element[9]  = "Java rulez !";[tab][/tab]$Text_Element[10] = "JavaScript rulez !";[tab][/tab]$Text_Element[11] = "ALGOL rulez !";[tab][/tab]$Text_Element[12] = "COBOL rulez !";[tab][/tab]$Text_Element[13] = "Delphi rulez !";[tab][/tab]$Text_Element[14] = "Pascal rulez !";[tab][/tab]$Text_Element[15] = "FORTRAN rulez !";[tab][/tab]$Text_Element[16] = "Ruby rulez !";[tab][/tab]$Text_Element[17] = "Eiffel rulez !";[tab][/tab]$Text_Element[18] = "PHP rulez !";[tab][/tab]$Text_Element[19] = "mySQL rulez !";[tab][/tab]$Text_Element[20] = "SmallTalk rulez !";[tab][/tab]$This_Second = date('s'); // "00" --- "59"[tab][/tab]$Text_Index = 1 + (int)($This_Second/3);[tab][/tab]$Random_Text = $Text_Element[$Text_Index];

Part [2] Create the Signature Image:

Job [2.1] Take a copy of the Template PNG Image that will serve as the background:

Job [2.1] Step [2.1.1] Determine the sizes:

[tab][/tab]$New_Width = 308;[tab][/tab]$New_Height = 123;

Job [2.1] Step [2.1.2] Identify the Template PNG Image:

[tab][/tab]$Source_Image_Name = "template.png";

Job [2.1] Step [2.1.3] Create a copy the Template PNG Image in a memory structure:

[tab][/tab]$New_Image = ImageCreateFromPNG($Source_Image_Name) or die("Problem In Opening The Source Template Image");

Job [2.2] Write the 3 lines of text, and the 2 lines of signature, inside the new PNG image:

Job [2.2] Step [2.2.1] Determine the geometry --- in order to position correctly:

[tab][/tab]$Label_Width = 304;[tab][/tab]$Label_Height = 55;[tab][/tab]$Label_1_X_Offset = 2;[tab][/tab]$Label_1_Y_Offset = 10;[tab][/tab]$Label_2_X_Offset = 2;[tab][/tab]$Label_2_Y_Offset = 26;[tab][/tab]$Label_3_X_Offset = 2;[tab][/tab]$Label_3_Y_Offset = 42;[tab][/tab]$Sign_1_X_Offset = 2;[tab][/tab]$Sign_1_Y_Offset = 82;[tab][/tab]$Sign_2_X_Offset = 2;[tab][/tab]$Sign_2_Y_Offset = 98;

Job [2.2] Step [2.2.2] Determine the colors to be used:

[tab][/tab]$Default_Color = ImageColorAllocate($New_Image, 0xFE, 0xFE, 0xFE);[tab][/tab]$Label_Color = ImageColorAllocate($New_Image, 0, 0, 0);             // must already be in the palette ![tab][/tab]$Sign_Color = ImageColorAllocate($New_Image, 151, 75, 51);          // must already be in the palette !

Job [2.2] Step [2.2.3] Determine the texts for the 3 text lines, and the 2 lines of signature:

[tab][/tab]$Label_Text_1 = "You are $SurferAddress at $SurferProvider";[tab][/tab]$Label_Text_2 = "You use $SurferBrowser on $SurferOs";[tab][/tab]$Label_Text_3 = $Random_Text;[tab][/tab]$Label_Font = 2; // 1 = mono (too small) --- 2 = mono-in-thin --- 3 = 2-in-bold (too large)[tab][/tab]$Sign_Text_1 = "Greetings,";[tab][/tab]$Sign_Text_2 = "John";[tab][/tab]$Sign_Font = 3; // 3 = mono-in-bold --- 4 = large-mono-in-thin (too large) --- 5 = 4-in-bold (too large)

Job [2.2] Step [2.2.4] Determine the sizes of the text lines, depending on font and content:

[tab][/tab]$Label_Text_1_Width = ImageFontWidth($Label_Font) * strlen($Label_Text_1);[tab][/tab]$Label_Text_2_Width = ImageFontWidth($Label_Font) * strlen($Label_Text_2);[tab][/tab]$Label_Text_3_Width = ImageFontWidth($Label_Font) * strlen($Label_Text_3);

Job [2.2] Step [2.2.5] Determine the place of the text lines: 3 centered, and 2 left aligned:

[tab][/tab]$Label_Text_1_X = $Label_1_X_Offset + ( ($Label_Width - $Label_Text_1_Width) / 2 );[tab][/tab]$Label_Text_1_Y = $Label_1_Y_Offset;[tab][/tab]$Label_Text_2_X = $Label_2_X_Offset + ( ($Label_Width - $Label_Text_2_Width) / 2 );[tab][/tab]$Label_Text_2_Y = $Label_2_Y_Offset;[tab][/tab]$Label_Text_3_X = $Label_3_X_Offset + ( ($Label_Width - $Label_Text_3_Width) / 2 );[tab][/tab]$Label_Text_3_Y = $Label_3_Y_Offset;[tab][/tab]$Sign_Text_1_X = $Sign_1_X_Offset;[tab][/tab]$Sign_Text_1_Y = $Sign_1_Y_Offset;[tab][/tab]$Sign_Text_2_X = $Sign_2_X_Offset;[tab][/tab]$Sign_Text_2_Y = $Sign_2_Y_Offset;

Job [2.2] Step [2.2.6] Draw the text lines:

[tab][/tab]ImageString($New_Image, $Label_Font, $Label_Text_1_X, $Label_Text_1_Y, $Label_Text_1, $Label_Color);[tab][/tab]ImageString($New_Image, $Label_Font, $Label_Text_2_X, $Label_Text_2_Y, $Label_Text_2, $Label_Color);[tab][/tab]ImageString($New_Image, $Label_Font, $Label_Text_3_X, $Label_Text_3_Y, $Label_Text_3, $Label_Color);[tab][/tab]ImageString($New_Image, $Sign_Font, $Sign_Text_1_X, $Sign_Text_1_Y, $Sign_Text_1, $Sign_Color);[tab][/tab]ImageString($New_Image, $Sign_Font, $Sign_Text_2_X, $Sign_Text_2_Y, $Sign_Text_2, $Sign_Color);

Job [2.3] Write the new PNG image via http to the browser of the surfer:

[tab][/tab]header("Content-type: image/png");[tab][/tab]ImagePNG($New_Image);

I hope that the comments explain what is going on
to produce the following result: (refresh to see the changes...)

Share this post


Link to post
Share on other sites

This is really cool! Question: Is this what J-sig does? Because everytime I see M^E's signature I'm like, I want one.... but there's no client for Mac for J-sig, so I might have to resort to making my own?

Share this post


Link to post
Share on other sites

Dear chiiyo,After reading your post, I went to investigate J-sig.Indeed, the creation of the J-sig image is probably donein the same way as my prototype.But where J-sig differs is in the data that J-sig displays:First, the J-sig server script captures informationabout the surfers's browser, just like my prototype does.Second, the J-sig server script captures informationabout the J-sig subscriber's own machine, and in orderto do so, the J-sig subscriber needs to install the J-sigsoftware on his/her PC.This is in fact some sort of privacy intrusion, don't you think?What I want to do now:I need a PHP/mySQL hosting service, because my idea isto use a mySQL database.First, I will store in the mySQL database the texts thatare to be displayed inside the signature image.This will have to be done for each user.Second, I will have to write a PHP dialog that will allownew users to subscribe to the signature image service,and that will allow existing users to modify their texts.Third, I will store in the mySQL database the hits on thesignature images, when a surfers displays the image.Fourth, I will have to write a PHP script to draw an imagewith the statistics of the hits on each user's signature image.This chart image will function in the same manner as thesignature image itself, now that I know how to do that.Fifth, I will store in the mySQL database the TCP/IP addressesof all the Internet Service Providers in the world, togetherwith their Country-codes. The raw data - in CSV format - is freely available on the Internet.I have already programmed the SQL to load a mySQLdatabase with this information on my home test-server.Sixth, I will modify the PHP that draws the signature image,and the PHP that draws the hit-chart, and include the Country-codeof the surfers that view the signature images.Just like J-sig does.Now you see why I need a PHP/mySQL hosting service....

Share this post


Link to post
Share on other sites

Cool, sounds like you have a plan! If I understand you correctly, if you actually set up this thing, you'd be able to offer the services J-sig offers without requiring people to download and install any software, is that correct? That'll be really cool, since currently J-sig only caters to people using Windows software, and that's really sad!If you ever intend to set it up, and need graphics, just give a holler! People around here are very helpful in that. I should be able to hook you up with a few bases.

Share this post


Link to post
Share on other sites

By the way I was surfing through the Whatpulse Signature generation site (whatpulse.afraid.org) and they had a little section where they teach you how to do what you just did. I haven't read through the entire thing yet (I don't know PHP) but I'll just give the link here for other people interested in doing this but also like me, don't understand PHP...

http://forums.xisto.com/no_longer_exists/

Share this post


Link to post
Share on other sites

Dear chiiyo,


Thank you for pointing us to the Whatpulse site.

I have picked up an idea for my hit-chart graph:
(point 6 in my previous post)

Originally I wanted to show a statistical graph
of all the hits on the user's signature image,
based on the Country-code of the surfers.
But now I will try to show also the Country-flags
on the chart, if I can find all of them.
But

Google is my friend !


I suppose that will be almost 250 flag images.



P.S. Sorry that you do not (yet) understand PHP.
Every computer language is easy,
with the reference books by your side...
and some friendly forum members on the 'net...

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
Sign in to follow this  

×
×
  • 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.