Common PHP Graphics processing functions

Source: Internet
Author: User
Tags image identifier

1. Imagecreatetruecolor () Create a new true color image
Resource Imagecreatetruecolor (int x_size, int y_size)
Imagecreatetruecolor () returns an image identifier representing a black image with a size of x_size and y_size.

2. Imagecolorallocate () assigns a color to an image
int Imagecolorallocate (resource image, int red, int green, int blue)
Imagecolorallocate () returns an identifier that represents a color made up of a given RGB component. Red,green and Blue are the red, green, and blue components of the desired color respectively.

3. Imagefill () area fill
BOOL Imagefill (resource image, int x, int y, int color)
Imagefill () performs an area fill with a color color at the coordinates x, y (0, 0) of the image image (that is, the same as x, Y point color, and adjacent points are populated).

4. Imagestring () to draw a line of strings horizontally
BOOL Imagestring (resource image, int font, int x, int y, string s, int col)
Imagestring () uses the Col color to draw the string s to the x, y coordinates of the image represented by image (this is the upper-left coordinate of the string, and the upper-left corner of the entire image is 0,0). If the font is 1,2,3,4 or 5, the built-in font is used.

5. Imageline () draw a line segment
BOOL Imageline (resource image, int x1, int y1, int x2, int y2, int color)
Imageline () Draws a line segment from coordinates x1,y1 to X2,y2 (0, 0 in the upper left corner of the image) with a color color.

6. Imagesetpixel () draw a single pixel
BOOL Imagesetpixel (resource image, int x, int y, int color)
Imagesetpixel () Draws a point on the image with a color in x, y coordinates (0,0 in the upper-left corner of the image).

7. Imagettftext () writing text to an image with TrueType fonts
Array Imagettftext (resource image, float size, float angle, int x, int y, int color, string fontfile, string text)
Image Resource
Size font Sizes
Angle angle, 0 degrees is the text that reads from left to right. Higher value indicates counterclockwise rotation
X defines the first character's basic point (presumably the lower-left corner of the character) by the coordinates represented by X. x and Y
Y y-coordinate. It sets the position of the font baseline, not the bottom of the character.
Color index. Use negative color index values to turn off anti-aliasing effects
Fontfile is the path to the TrueType font you want to use.
Text string to be written by text

8. Imagecreatefrompng () Create a new image from a PNG file or URL
Resource Imagecreatefrompng (string filename)
Imagecreatefrompng () returns an image identifier that represents the image obtained from the given file name.

9. imagecopyresampled () resample copy part of image and resize
BOOL Imagecopyresampled (Resource Dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, I NT Dst_h, int src_w, int src_h)
Imagecopyresampled () copies a square area of an image into another image, inserting the pixel values smoothly, thus, in particular, reducing the size of the image and still maintaining great clarity. Returns TRUE if successful, and FALSE if it fails.

PHP generates a Simple Mail icon code

Header (' content-type:image/png '); $img =imagecreatetruecolor (400,200); $blue =imagecolorallocate ($img, 0,102,255); $ White=imagecolorallocate ($img, 255,255,255); Imagefill ($img, 0,0, $blue); Imagestring ($img, 2,130,50, ' Emailto:[email Protected], $white), Imageline ($img, 0,0,400,200, $white) imageline ($img, 0,200,400,0, $white); for ($i =0; $i <200;$ i++) {Imagesetpixel ($img, Rand (0,400), Rand (0,200), $white);} $font = ' C:\WINDOWS\Fonts\SIMKAI.  TTF '; $text =iconv (' utf-8 ', ' utf-8 ', ' Recipient: Administrator '); Imagettftext ($img, 20,0,108,40, $white, $font, $text); Imagepng ($img); Imagedestroy ($img);

Common PHP Graphics processing functions

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.