Functions of the php-GD library (1)

Source: Internet
Author: User

<? Php // getimagesize-get the image size [that is, the length and width] // print_r (getimagesize (". /logo_ I .gif ")); // Array ([0] => 240 [1] => 124 [2] => 1 [3] => width = "240" height = "124" [bits] => 8 [channels] => 3 [mime] => image/gif) // image_type_to_mime_type-obtains the MIME type of the image type returned by getimagesize, exif_read_data, exif_thumbnail, and exif_imagetype. // $ aa = getimagesize (". /logo_ I .gif "); // print_r (image_type_to_mime_type ($ aa); // imagearc-draw an Elliptical Arc/* B Ool imagearc (resource $ image, int $ cx, int $ cy, int $ w, int $ h, int $ s, int $ e, int $ color ); // $ image: Resource // $ cx: left-side center-exclusive position/$ cy: top-side center-exclusive position/$ w: Circle Diameter left/$ h: circle Diameter up/down/$ s: 0 degrees clockwise // $ e: 360 // $ color: circle color // create a 200X200 Image $ img = imagecreatetruecolor (200,200); // assign color $ white = imagecolorallocate ($ img, 255,255,255 ); $ black = imagecolorallocate ($ img, 0, 0, 0); // draw a white circle imagearc ($ img, 100,100,150,150, 0,360, $ White); // output the image to the browser header ("Content-type: image/png"); imagepng ($ img); // release the memory imagedestroy ($ img ); * // imagechar-draw a character horizontally/* bool imagechar (resource $ image, int $ font, int $ x, int $ y, string $ c, int $ color) $ image: Resource $ font: font size $ x: distance between the text and the Left Border $ y: distance between the text and the top border $ c: draw the first character of string c in the image-specified image $ color: text color $ im = imagecreate (100,100); $ string = 'php '; $ bg = imagecolorallocate ($ im, 255,255,255); $ black = imageco Lorallocate ($ im, 0, 0, 0); // prints a black "P" in the top left cornerimagechar ($ im, 1, 0, 0, $ string, $ black); header ('content-type: image/png '); imagepng ($ im ); * // imagecharup-draw a character vertically/* bool imagecharup (resource $ image, int $ font, int $ x, int $ y, string $ c, int $ color) $ image: Resource $ font: font size $ x: distance between the text and the Left Border $ y: distance between the text and the top border $ c: draw the first character of string c into the image specified by the image $ color: color of the text $ im = imagecreate (100,100); $ string = 'Note that the first letter is a n'; $ bg = imagecolorallocate ($ im, 255,255,255); $ black = imagecolorallocate ($ im, 0, 0, 0 ); // prints a black "Z" on a white backgroundimagecharup ($ im, 3, 10, 10, $ string, $ black); header ('content-type: image/png '); imagepng ($ im); * // imagecolorallocate-assign color to an image/* int imagecolorallocate (resource $ image, int $ red, int $ green, int $ blue) $ image: image resources $ red, $ green, $ bl Ue is the red, green, and blue components of the required colors. These parameters are integers ranging from 0 to 255 or hexadecimal values 0x00 to 0xFF () the call will fill the background color $ im = imagecreate (100,100); // set the background color to Red $ background = imagecolorallocate ($ im, 255, 0, 0 ); // set some colors $ white = imagecolorallocate ($ im, 255,255,255); $ black = imagecolorallocate ($ im, 0, 0, 0 ); // hexadecimal mode $ white = imagecolorallocate ($ im, 0xFF, 0xFF, 0xFF); $ black = imagecolorallocate ($ im, 0x00, 0x00, 0x00); header ('content-type: im Age/png '); imagepng ($ im); * // imagecolorallocatealpha-assign color + alpha/* int imagecolorallocatealpha (resource $ image, int $ red, int $ green, int $ blue, int $ alpha) imagecolorallocatealpha () has the same behavior as imagecolorallocate (), but has an additional transparency parameter alpha with a value ranging from 0 to 127. 0 indicates full opacity, and 127 indicates full transparency. $ Size = 300; $ image = imagecreatetruecolor ($ size, $ size); // draw a box with a white background and a black border $ back = imagecolorallocate ($ image, 255,255,255 ); $ border = imagecolorallocate ($ image, 0, 0, 0); imagefilledrectangle ($ image, 0, 0, $ size-1, $ size-1, $ back ); imagerectangle ($ image, 0, 0, $ size-1, $ size-1, $ border); $ yellow_x = 100; $ yellow_y = 75; $ red_x = 120; $ red_y = 165; $ blue_x = 187; $ blue_y = 125; $ radius = 150; // use alpha Value allocation colors $ yellow = imagecolorallocatealpha ($ image, 255,255, 0, 75); $ red = imagecolorallocatealpha ($ image, 255, 0, 0, 75 ); $ blue = imagecolorallocatealpha ($ image, 0, 0,255, 75); // draw three overlapping circles imagefilledellipse ($ image, $ yellow_x, $ yellow_y, $ radius, $ radius, $ yellow); imagefilledellipse ($ image, $ red_x, $ red_y, $ radius, $ radius, $ red); imagefilledellipse ($ image, $ blue_x, $ blue_y, $ radius, $ radius, $ blue );// Do not forget to output the correct header! Header ('content-type: image/png '); // The final output result imagepng ($ image); imagedestroy ($ image ); * // imagecolordeallocate-cancel image color allocation/* bool imagecolordeallocate (resource $ image, int $ color) imagecolordeallocate () function cancel previous imagecolorallocate () or imagecolorallocatealpha () the allocated color. $ Im = imagecreate (100,100); // set the background to Red $ background = imagecolorallocate ($ im, 255, 0, 0 ); // set some colors $ white = imagecolorallocate ($ im, 255,255,255); imagecolordeallocate ($ im, $ white); header ('content-type: image/png '); imagepng ($ im); * // imagecolorexact-get the index value of the specified color/* int imagecolorexact (resource $ image, int $ red, int $ green, int $ blue) returns the index value of the specified color in the image palette. If the color is not in the image palette,-1 is returned. If an image is created from a file, only the colors used in the image will be analyzed. Colors that appear only in the color palette are not analyzed. $ Im = imagecreate (100,100); // set the background to Red $ background = imagecolorallocate ($ im, 255, 0, 0 ); // set some colors $ white = imagecolorallocate ($ im, 255,255,255); $ aa = imagecolorexact ($ im, 255, 0, 0); echo $ aa; // if no value exists, return-1 * // imagecolorset-set the color for the specified palette index/* void imagecolorset (resource $ image, int $ index, int $ red, int $ green, int $ blue) This function sets the index specified in the palette to the specified color. $ Im = imagecreate (100,100); $ background = imagecolorallocate ($ im, 255, 0, 0); for ($ c = 0; $ c <50; $ c ++) {imagecolorset ($ im, $ c, 255,255,255);} header ('content-type: image/png '); imagepng ($ im ); * // imagecolortransparent-define a color as transparent/* int imagecolortransparent (resource $ image [, int $ color]) imagecolortransparent () to set the transparent color in the image to color. Image is the image identifier returned by imagecreatetruecolor (), and color is the color identifier returned by imagecolorallocate. $ Im = imagecreate (100,100); $ background = imagecolorallocate ($ im, 0, 0, 0); imagecolortransparent ($ im, $ background); header ('content-type: image/png '); imagepng ($ im); */?>

 

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.