PHP in the GD library (GO)

Source: Internet
Author: User
Tags 0xc0

"Some simple use of the GD Library in PHP": Keywords:php in the GD library some simple use

Today understand some of the simple use of GD library, now a little to summarize!

What is the GD library? , graphic device, Image tool Library, GD Library is an extension of PHP processing graphics, the GD library provides a series of APIs to handle images, use the GD library to process images, or create images. The GD library on the site is often used to generate thumbnails or to add watermarks to images or generate reports on site data.

PHP is not limited to outputting HTML text. PHP can also be used to dynamically output images, such as text buttons, verification codes, data charts, etc. by using the GD extension library. Ha can easily edit images, try to handle thumbnails and add watermarks to images, etc., with powerful image processing capabilities.

First of all, let's say a few steps of the GD library to draw a simple graph:

1, the first is to create a canvas, here we use the Imagecreatetruecolor function, you can also use imagecreate, the difference is that the former creates a true color image, the latter created a color palette-based image

$img =imagecreatetruecolor (100,100), of which two parameters correspond, the width and height of the image we created

2, set up some necessary "dye box"

is actually

This article from: Macaidong Blog Reprint please specify the source URL: http://www.makaidong.com

Define some of the fill colors that will be used later, where we are uniformly defined here, where we use the Imagecolorallocate function

$white =imagecolorallocate ($img, 0xff,0xff,0xff) or can use RGB color naming methods such as $white=imagecolorallocate ($img, 255,255,255);

$gray = Imagecolorallocate ($img, 0xc0, 0xc0, 0xc0);  $darkgray = Imagecolorallocate ();  $navy = Imagecolorallocate ();  $darknavy = Imagecolorallocate ();  $red = Imagecolorallocate ();  $darkred = Imagecolorallocate ();  $black =imagecolorallocate ( $img, 0x00,0x00,0x00);   

Here we define more of the required colors

3, fill area color, can be easily understood as the background color of the fill picture, using the Imagefill function

Imagefill ($img, 0,0, $white), where 0 0 indicates that the background color is filled starting at coordinates x y

4, draw the graph, for example to draw the pie chart, need is Imagefilledarc function

The parameters of Imagefilledarc () are relatively more, shaped like Imagefilledarc ($img, $red, $i, 100,50,0,45, Img_arc_pie);

It is represented by the red color word img image on the drawing of a $i as a starting point, with 0 45 angle to draw an arc in this range

5, during the period we can also add a few explanatory questions, such as adding a string horizontally, using imagestring ($img, 1,20,40, "hello,world!", $red), in the IMG image with 20 40 as the coordinates, write a red Hello, world! Words

6, is to speak the image output

The first thing to tell is which image format the browser will output, such as PNG output, using the header ("Content-type:image/png");

Next, the picture is exported to the browser, imagepng ($img);

Finally, destroy the image, i.e. release the Memory Imagedestroy (IMG) occupied by the picture storage;


Search this article related articles:php in the GD Library of some simple use this article link: http://www.makaidong.com/%E5%8D%9A%E5%AE%A2%E5%9B%AD%E6%9C%89/16352. shtml Reprint Please specify the Source: PHP in the GD Library of some simple use-blog Park

PHP in the GD library (GO)

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.