Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Forum Signature-image With Php, Use PHP to create an image in real-time
signatureimage
post Apr 16 2005, 10:24 AM
Post #1


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 51
Joined: 16-April 05
Member No.: 4,048



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.


This post has been edited by microscopic^earthling: Apr 16 2005, 10:39 AM
Go to the top of the page
 
+Quote Post
miCRoSCoPiC^eaRt...
post Apr 16 2005, 10:48 AM
Post #2


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,242
Joined: 29-January 05
From: Nakorn Chaisri, Thailand
Member No.: 2,411



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.

CODE
<?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://codesample.microsys-asia.info/ipsig.php
Go to the top of the page
 
+Quote Post
signatureimage
post Apr 18 2005, 05:26 PM
Post #3


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 51
Joined: 16-April 05
Member No.: 4,048



First:
Thank you for moving my post into the correct forum group.

Second:
Thank you for putting me on the right programming track.

Third:
Now that I know how to start, I will use my home test-server
to program the signature image.
Go to the top of the page
 
+Quote Post
signatureimage
post Apr 18 2005, 08:39 PM
Post #4


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 51
Joined: 16-April 05
Member No.: 4,048



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:

CODE
$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:

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


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

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


Job [1.3] Find the name of the browser:

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


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

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


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

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

CODE
$New_Width = 308;
$New_Height = 123;


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

CODE
$Source_Image_Name = "template.png";


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

CODE
$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:

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


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

CODE
$Default_Color = ImageColorAllocate($New_Image, 0xFE, 0xFE, 0xFE);
$Label_Color = ImageColorAllocate($New_Image, 0, 0, 0);             // must already be in the palette !
$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:

CODE
$Label_Text_1 = "You are $SurferAddress at $SurferProvider";
$Label_Text_2 = "You use $SurferBrowser on $SurferOs";
$Label_Text_3 = $Random_Text;
$Label_Font = 2; // 1 = mono (too small) --- 2 = mono-in-thin --- 3 = 2-in-bold (too large)

$Sign_Text_1 = "Greetings,";
$Sign_Text_2 = "John";
$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:

CODE
$Label_Text_1_Width = ImageFontWidth($Label_Font) * strlen($Label_Text_1);
$Label_Text_2_Width = ImageFontWidth($Label_Font) * strlen($Label_Text_2);
$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:

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


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

CODE
ImageString($New_Image, $Label_Font, $Label_Text_1_X, $Label_Text_1_Y, $Label_Text_1, $Label_Color);
ImageString($New_Image, $Label_Font, $Label_Text_2_X, $Label_Text_2_Y, $Label_Text_2, $Label_Color);
ImageString($New_Image, $Label_Font, $Label_Text_3_X, $Label_Text_3_Y, $Label_Text_3, $Label_Color);
ImageString($New_Image, $Sign_Font, $Sign_Text_1_X, $Sign_Text_1_Y, $Sign_Text_1, $Sign_Color);
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:

CODE
header("Content-type: image/png");
ImagePNG($New_Image);


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

Go to the top of the page
 
+Quote Post
chiiyo
post Apr 19 2005, 02:24 AM
Post #5


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041



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?
Go to the top of the page
 
+Quote Post
signatureimage
post Apr 19 2005, 11:13 AM
Post #6


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 51
Joined: 16-April 05
Member No.: 4,048



Dear chiiyo,


After reading your post, I went to investigate J-sig.

Indeed, the creation of the J-sig image is probably done
in 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 information
about the surfers's browser, just like my prototype does.

Second, the J-sig server script captures information
about the J-sig subscriber's own machine, and in order
to do so, the J-sig subscriber needs to install the J-sig
software 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 is
to use a mySQL database.

First, I will store in the mySQL database the texts that
are 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 allow
new 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 the
signature images, when a surfers displays the image.

Fourth, I will have to write a PHP script to draw an image
with the statistics of the hits on each user's signature image.
This chart image will function in the same manner as the
signature image itself, now that I know how to do that.

Fifth, I will store in the mySQL database the TCP/IP addresses
of all the Internet Service Providers in the world, together
with their Country-codes.
The raw data - in CSV format - is freely available on the Internet.
I have already programmed the SQL to load a mySQL
database 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-code
of the surfers that view the signature images.
Just like J-sig does.


Now you see why I need a PHP/mySQL hosting service....


Go to the top of the page
 
+Quote Post
chiiyo
post Apr 19 2005, 01:18 PM
Post #7


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041



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.
Go to the top of the page
 
+Quote Post
chiiyo
post Apr 19 2005, 06:22 PM
Post #8


Premium Member
Group Icon

Group: Members
Posts: 218
Joined: 14-March 05
From: Singapore
Member No.: 3,041



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://whatpulse.afraid.org/how/
Go to the top of the page
 
+Quote Post
signatureimage
post Apr 19 2005, 10:54 PM
Post #9


Member [ Level 2 ]
Group Icon

Group: Members
Posts: 51
Joined: 16-April 05
Member No.: 4,048



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
QUOTE
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...
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How To Mount A Cd Image(13)
  2. Error 406 - Problem In My Phpbb Forum(8)
  3. How To: Create PDF With Php(18)
  4. Task Mgr. Has Been Disabled By Your Administrator(6)
  5. How Do I Create A Good Fire Animation Using Flash ?(13)
  6. Anyone Know Of Any Good Image Editing Software?(23)
  7. Image Resizer Power Toy(2)
  8. Forum Based Multiplayer RPG(11)
  9. Uploading Image File Through JSP Code To Server(9)
  10. Help Me Create A Text-based, Turn-based Game(9)
  11. Add A Forum To Your Site(23)
  12. The Cloning Issue(43)
  13. Can You Create A Folder Name "con"(17)
  14. How To Create A Good Forum(28)
  15. Real Driving(17)
  1. Best Games Of All Time(15)
  2. How Do I Create Static Routes In Windows Xp?(11)
  3. Timeshift Discussion(2)
  4. How To Create Your Own Proxy Site (free And Easy)(13)
  5. Best Free Forum Software(10)
  6. How Do You Create A Vista?(21)
  7. Free Signature Thread(3)
  8. Image Problems With Windows 2000(8)
  9. Back After Long Time(1)
  10. Create An Animation With Powerpoint(1)
  11. Create An Ftp Server On Your Pc With Serv-u(1)
  12. Like My Signature?(3)
  13. What You Need Before You Can Create A Text-based Game..(5)


 



- Lo-Fi Version Time is now: 6th September 2008 - 07:31 AM