Image function _php

Source: Internet
Author: User
There is a set of image functions in PHP that can dynamically generate the image data stream in GIF format and output it to the server. In order for this set of functions to work, the system must have the support of the GD library. If it is under UNIX, you should get GD source code and compile it before compiling PHP, generate libgd.a and some. h files, and copy them to the system's library directory and header file directory (for example,/usr/lib and/usr/ Include); if it is under Windows, the PHP3.0 installer installs a Gd.dll file, adding a ' DL ' ("Gd.dll") to the program; ' You can use the image function.

The main image functions are:

(1) Imagecreate (width, height)

Returns an image descriptor.

 

(2) Imagecreatefromgif (file name);

Returns an image descriptor.

 

(3) Imagecolorallocate (image descriptor, red, green, blue);

Returns a color descriptor. Since the GIF image can only have 256 colors, it must be assigned a palette, which is assigned a palette item.

 

(4) Imagecolortransparent (image descriptor, color descriptor);

Specifies that a color is a transparent color.

 

(5) Imagearc (Image descriptor, center horizontal axis, center ordinate, ellipse width, ellipse height, start angle, terminating angle, color descriptor);

Imagechar (image descriptor, font, x, y, character, color descriptor);

Imagecharup (image descriptor, font, x, y, character, color descriptor);

Imagecopyresized (target image descriptor, source image descriptor, target x, target y, source x, source y, target width, target height, source width, source height);

Imagedashedline (Image descriptor, x1,y1,x2,y2, color descriptor);

Imagefill (Image descriptor, starting point x, starting point y, color descriptor);

Imagefilledpolygon (image descriptor, each vertex array, vertex number, color descriptor);

Imagefilledrectangle (Image descriptor, x1,y1,x2,y2, color descriptor);

Imagefilltoborder (Image descriptor, starting point x, starting point y, border color, fill color);

Imageline (Image descriptor, x1,y1,x2,y2, color descriptor);

Imagepolygon (image descriptor, each vertex array, vertex number, color descriptor);

Imagerectangle (Image descriptor, x1,y1,x2,y2, color descriptor);

Imagesetpixel (Image descriptor, x, y, color descriptor);

Imagestring (image descriptor, font, x, y, string, color descriptor);

Imagestringup (image descriptor, font, x, y, string, color descriptor);

These are drawing functions, which need to be explained in order to keep the 1th x, 1th y, 2nd x, 2nd y,... in the vertex array of the polygon.

 

(6) Imageloadfont (file name);

The file should be a bitmap font file that returns a font number. The system defaults to 1-5 font numbers and can be used directly.

 

(7) Imagesx,imagesy

Get the width and height of an image separately, and receive an image descriptor parameter.

 

(8) Imagecolorat (Image descriptor, x, y);

Imagecolorclosest (image descriptor, red, green, blue);

Imagecolorexact (image descriptor, red, green, blue);

Imagecolorset (image descriptor, color descriptor, red, green, blue);

Imagecolorsforindex (image descriptor, color descriptor);

Imagecolorstotal (image descriptor);

The first three returns a color descriptor. Imagecolorexact returns 1 if no match is found.

Imagecolorsforindex returns an array of three items, with the elements red, green, and blue respectively.

Imagecolorstotal returns the total number of colors.

 

(9) Imagefontheight,imagefontwidth

Receives a font number as an argument.

 

(10) Imagegif (image descriptor, [filename]);

If no file name is available, the GIF stream is sent to the browser. At this point, the program should have a first sentence: Header ("Content-type:image/gif")

 

(11) Imagedestroy (image descriptor);

There is a small bug in the image function (at least in the PHP3.0RC and PHP3.0RC3 for UNIX source code has been found, now www.php.net on the download file should have been changed), that is, Imagesetpixel always draw points at (Y,y), No matter what the value of x is, the problem is not very large.
  • 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.