 |
usdrunk Level: Protégé
 Registered: 20-03-2006 Posts: 6
|
Dynamic image
Hi,
I wonder how people can make the dynamic image, like Alexa ranking button, or dynamic sign (have IP address, browser infomation...) How can they do that?
I don't know exactly where I can post this thing, so I post here.
Thankx
|
|
26-03-2006 at 12:28 AM |
|
|
admin Level: Administrator

 Registered: 04-04-2002 Posts: 35
|
Re: Dynamic image
this is a little script I use to generate a random number inside a picture to validate user regitration:
<?php
/*Send header*/
Header("Content-Type: image/png");
/* initialize a session. */
session_start();
/*We'll set this variable later.*/
$new_string;
/*register the session variable. */
session_register('new_string');
/* set up image*/
/*The first number is the width and the second is the height*/
$im = ImageCreate(200, 40);
/*creates two variable to store color*/
$white = ImageColorAllocate($im, 255, 255, 255);
$black = ImageColorAllocate($im, 0, 0, 0);
/*random string generator.*/
/*The seed for the random number*/
srand((double)microtime()*1000000);
/*Runs the string through the md5 function--which is a function
that encrypts a string, changing it into a 32 character string
composed of numbers and lowercase letters*/
$string = md5(rand(0,9999));
/*Creates the new string. The first number is the point in the 32
character string where we will pull our string from. In other
words, PHP will count (beginning at 0) 17 characters into the
string. The 18th character in will be our beginning point
(remember, PHP starts counting from 0). From there, PHP
counts 5 characters from that point, and thus, we get our five
character string. The second number is the length of our
string--changing this number will give us different string
lengths.*/
$new_string = substr($string, 17, 5);
/*fill image with black*/
ImageFill($im, 0, 0, $black);
/*write string at coordinates (70,10) in the color white. (70, 10)
puts the string almost in the middle of the image.*/
ImageString($im, 4, 70, 10, $new_string, $white);
/*output to browser*/
ImagePNG($im);
ImageDestroy($im);
?>
|
then save this as verify.php
by adding in your html the reference to this you'll se a random number inside an image
<img src="verify.php">
[Edited by admin on 31-03-2006 at 07:30 AM GMT]
____________________________
AndreaVB
|
|
31-03-2006 at 06:29 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 16
|
Re: Dynamic image
What do you mean more knowledge? That's the answer of how to do it, how it's done, with an example!
____________________________
Everywhere's Local (pre-release), My company's website
|
|
07-04-2007 at 04:54 PM |
|
|
|
|
 |
 |