PHP has an extremely powerful image processing capability, which makes it easy to dynamically generate web images.
is a simple counter made using PHP.
1. General ideas:
Record the number of previous visits in a text file, and when the page is accessed, open the file from
And read out the past number of visitors, add 1, get the latest number of visitors, and format the number of
The standard format, and then call the image processing function, the output of the number into a picture, and then put the new access number back
Written in a document that records the number of visitors.
2. Description of functions used by the program:
A. Related file operations:
A. Open the file:
The prototype of the function: int fopen (string filename, string mode);
Returns the result: if the open file succeeds, the function returns a file stream pointer, otherwise FALSE (0) is returned.
Parameter description:
String filename--The name of the file to be opened must be in the form of a string.
For example, "Zzm.txt", ". \zzm.txt "and so on.
String mode-The way the file is opened must be in the form of a character.
' R ', read-only, the file pointer points to the beginning of the file
' r+ ', readable and writable, pointer to the beginning of the file
' W ', write-only form, file pointer to the beginning of the file, the length of the file truncated to 0,
If the file does not exist, it will attempt to create a file.
' w+ ', readable and writable, the file pointer points to the beginning of the file, the length of the file truncated to 0,
If the file does not exist, it will attempt to create a file.
' A ', append form (only writable), file pointer to the end of the file, if the text
The file does not exist and will attempt to build it.
' A + ', readable and writable, the file pointer pointing to the end of the file, if the file does not exist,
Will attempt to build the file.
Example: Open "Zzm.txt" below the current directory in read-only form
$fp = fopen ("Zzm.txt", "R");
B. Close the file:
Function prototype: int fclose (int fp);
Return result: Successfully returned 1, failure returned 0
Parameter description: The int FP is a file stream pointer returned by the fopen function.
Example: Close the Zzm.txt file that you just opened with fopen
Fclose ($FP);
C. Read the file:
Function prototype: string fgets (int fp, int length);
Returns the result: Returns a string of length length-1, if to the end of the file, returns EOF (end of file)
Parameter description:
int FP--The file stream pointer to be read into the data, the value returned by the fopen function
int length--the number of characters to read, the actual number of characters read into length-1
Example: Reading 9 characters from a $fp
$str 1 = fgets ($fp, 10);
D. Writing files:
function prototypes: int fputs (int fp, string str, int [length]);
Return results: Same as Fclose
Parameter description:
int FP--a file stream pointer to write information, the value returned by the fopen function
String STR-strings to write to the file.
int length--The length of the write, optional, if length is not provided, the entire string is written,
Otherwise, length characters are written.
Example: Write "0000000001" to $fp
Fput ($fp, "0000000001");
B. Related String Functions:
A. Calculating the length of a string:
Function prototype: int strlen (string str);
Return Result: The length of the returned string
Parameter description:
String STR--strings to be computed for length
Example: Calculating the string length of "000000000"
$str 2 = "000000000";
$len 2 = strlen ($STR);
B. String addition: The simplest, with one. Connect the two strings together.
Example: adding $str 1 and $STR2
$str = $str 1. $str 2
C. Related graphical functions:
A. Create a new Image:
function prototypes: int imagecreate (int x_size, int y_size);
Return result: Returns an empty image identification number (ImageID) with a x*y pixel size
Parameter description: X_size,y_size is the width and height (in pixels) of the new image, respectively
Example: Create an empty image with a 88*31 pixel size
$ImageID = Imagecreate (88, 31);
B. Assign a color to the image:
function prototypes: int imagecolorallocate (int im, int red, int green, int blue);
Return result: Returns an RGB color identification number to the image ($im)
Parameter description: int im image identification number
int red, green, blue are the three colors of red, green and blue respectively, the value range 0-255
Example: Assigning an image $im an identification number of $white white color, white RGB for (255,255,255)
$white = Imagecolorallocate ($im, 255, 255, 255);
C. Fill the image with color:
function prototypes: int imagefill (int im, int x, int y, int col);
Return Result: 1 returned successfully, otherwise 0
Parameter description: int IM, image identification number
int x, int y, fills the color from the (x, y) coordinates of the image
(0,0) indicates the upper-left corner of the image
int col, color identification number
Example: Fill in black from the upper left corner of the image (that is, the entire picture) (already using the Imagecolorallocate function
A black color identification number of $black is defined.
Imagefill ($im, 0, 0, $black);
D. Calculate the width of the image:
Function prototype: int imagesx (int im);
Return result: The width of the returned image (in pixels)
Parameter description: int IM, identification number of the image.
Example: Calculating the width of an image $im
$px = Imagesx ($im);
Detailed description; http://php.662p.com/thread-363-1-1.html