Functions of the GD Library in php (1)

Source: Internet
Author: User
This article describes in detail the development of PHP watermarks and thumbnails, Pphp image processing, and gd2 configuration file modification. Php gd Library Tutorials:
1. PHP watermark and thumbnail development tutorial
2. PHP watermark and thumbnail latest video tutorial
3. php image processing gd2 configuration file modification

// 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/* bool 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: Center-exclusive position/$ w: circle diameter left/$ h: circle diameter up/down/$ s: 0 degrees clockwise drawing // $ e: 360 // $ color: Circle color // create 200X200 images $ 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 = imagecolorallocate ($ 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 image Charup (resource $ image, int $ font, int $ x, int $ y, string $ c, int $ color) $ image: resource $ font: font Size $ x: distance from text to the left border $ y: distance from text to the top border $ c: draw the first character of string c in the image-specified image $ color: text color $ 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, $ s Tring, $ 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 resource $ red, $ green and $ blue are 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

The above is the php-GD library function (1) _ GD Library tutorial content, for more information, please follow the PHP Chinese network (www.php1.cn )!

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.