Php circle drawing method

Source: Internet
Author: User
Tags image identifier
This article describes how to draw a circle in php. It analyzes in detail the basic steps and implementation methods of drawing a circle in php. For more information, see

This article describes how to draw a circle in php. It analyzes in detail the basic steps and implementation methods of drawing a circle in php. For more information, see

This example describes how to draw a circle in php. Share it with you for your reference. The specific implementation method is as follows:

The basic steps for php plotting are as follows: (the extension = php_gb2.dll component in php. ini must be enabled first)

1. Create a canvas;

2. Draw the desired image (circle, straight line, rectangle, slice, arc .......);

3. output to a webpage or save it as another one;

4. Destroy the image (the purpose is to release the memory occupied by the image ).

Three most common image formats for website development: gif, jpg/jpeg, and png

(1) gif format: the maximum compression rate, but only 256 colors can be displayed, which may cause color loss. Advantage: animated images may be displayed.

(2) jpg/jpeg format: the compression ratio is also relatively high (lossy compression, may also lose some colors), and many web pages are used.

(3) png format: combining the advantages of gif and jpg, it cannot display animated images. High Fidelity, support lossless compression, and the best color storage, relatively larger than jpg/jpeg.

Php draws a circle with the following code:

The Code is as follows:

<? Php
// 1. Create a canvas
$ Im = imagecreatetruecolor (300,200); // create a real-color image. The default background is black and the image identifier is returned. Another function, imagecreate, is not recommended.
// 2. Draw the desired image
$ Red = imagecolorallocate ($ im, 255, 0, 0); // create a color for use
Imageellipse ($ im, 30, 40, 40, $ red); // draw a circle. Parameter description: 30, 30 is the center coordinate of the circle; 40, 40 is the width and height, when not the same as the elliptical; $ red is the circle color (Box color)
// 3. output image
Header ("content-type: image/png ");
Imagepng ($ im); // output to the page. If the second parameter [, $ filename] exists, the image is saved.
// 4. Destroy images and release memory
Imagedestroy ($ im );
?>

I hope this article will help you with php programming.

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.