Php Plotting Method

Source: Internet
Author: User
Php drawing preparation: (1) enable Image Library extensionphp_gd2.all to use the drawing function library in php. ini remove the semicolon in front of it and restart apache (load function library) php drawing steps: (1) create a canvas, the background is black by default $ imgimagecreatetruecolor (400,300) (-create a true color image x

Php drawing preparation: (1) enable Image Library extension = php_gd2.all to use the drawing function library in php. remove the semicolon in front of it in ini and restart apache (load function library) to draw php: (1) create a canvas. The default background is black $ img = imagecreatetruecolor (400,300) (-create a true color image x

Php drawing preparation:

(1) Enable Image Library extension = php_gd2.all to use the drawing function library, remove the semicolon in front of it in php. ini, and restart apache (load function library)

Php plot steps:

(1) create a canvas. The background is black by default.

$ Img = imagecreatetruecolor (400,300) (-create a true color image x = 400, y = 300)

(2) Draw the image (Circular, straight line, hold, arc, slice, etc)

$ Red = imagecolorallocate ($ img, 255, 0) (where int $ red =, int $ green = 0, int $ blue = 0, so that rbg is set to red)

Example 1:

(1) imageellipse ($ img, 20, $ red) (draw an elliptic, elliptical: a = 20 (width), B = 20 (height), center: x = 0, y = 0)

(2) imagefilledellipse ($ img, 20, $ red) (draw an elliptical filled color)

(3)Imagearc($ Img, Int$ Cx, Int$ Cy, Int$ W, Int$ H, Int$ S, Int$ E, Int$ Color) (Draw an elliptical arc)

The upper left corner of the image is 0, 0 ).ImageDraw an elliptical arc in the image.WAndHSpecify the width and height of the ellipse, respectively.SAndEThe parameter is specified as an angle. 0 ° at three o'clock, drawing clockwise

Example 2:

Load source Image

$ Srcimage = imagecreatefromgif ("image.gif ")

$ Srcimageinfo = getimagesize ("image.gif ")

Copy the image to the target canvas

Imagecopy ($ img, $ srcimage, $ srcimageinfo [0], $ srcimageinfo [1]) ($ srcimageinfo [0] long $ srcimageinfo [1] Wide)

Example 3:

Imagestring ($ img, 5, 0, 0, "hellow word", $ red)

If you want to write Chinese

$ Str = "world"

Imagettftext ($ img, 30, 0, 40, 40, $ red, "font", $ str) (where "font": use C: \ Copy the library in the Windows \ Fonts file to the current file for reference)

Imagettftext(Resource$ Image, Float$ Size, Float$ Angle, Int$ X, Int$ Y, Int$ Color, String$ Fontfile, String$ Text)

(3) the image can be output to a webpage or saved separately.

Header ("content-type: image/png") (this is set here. It is accepted as an image when being transmitted over http)

Imagepng ($ img) (output image)

(4) destroy the image (release the memory here the image is on the server)

Imagedestory ($ img)

Popular image formats:

The GIF image has a high compression rate but can only display 256 colors. The color may be lost and the animation effect can be displayed.

Jpg/jpeg images have a high compression rate and can be displayed with smaller files. Many webpages are used.

Png this format combines the advantages of gif and jpg, but cannot display animations

Selection Method:

The color must be png (for example, an antique auction photo) with high fidelity. A large or small gif image is required, and a jpg image is generally used.

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.