PHP creates a 3D sector statistical chart and scales the image.

Source: Internet
Author: User
Tags 0xc0
This article mainly introduces how to create a 3D slice Statistical Chart using PHP and how to scale the image. For more information, see

This article mainly introduces how to create a 3D slice Statistical Chart using PHP and how to scale the image. For more information, see

1. Use functions of the php gd library to draw a 3D sector Statistical Chart

<? Php
Header ("content-type", "text/html; charset = UTF-8 ");
/* Sector statistical chart */
$ Image = imagecreatetruecolor (100,100);/* Create a canvas */
/* Set the color required for the canvas */
$ White = imagecolorallocate ($ image, 0xff, 0xff, 0xff );
$ Gray = imagecolorallocate ($ image, 0xc0, 0xc0, 0xc0 );
$ Darkgray = imagecolorallocate ($ image, 0x90, 0x90, 0x90 );
$ Navy = imagecolorallocate ($ image, 0x00, 0x00, 0x80 );
$ Darknavy = imagecolorallocate ($ image, 0x00, 0x00, 0x50 );
$ Red = imagecolorallocate ($ image, 0xff, 0x00, 0x00 );
$ Darkred = imagecolorallocate ($ image, 0x90, 0x00, 0x00 );
/* Fill in the background color */
Imagefill ($ image, 0, 0, $ white );
/* 3D production */
For ($ I = 60; $ I> 50; $ I --)
{
Imagefilledarc ($ image, 50, $ I, 100, 50,-160, 40, $ darknavy, IMG_ARC_PIE );
Imagefilledarc ($ image, 50, $ I, 100, 50, 40, 75, $ darkgray, IMG_ARC_PIE );
Imagefilledarc ($ image, 50, $ I, 100, 50, 75,200, $ darkred, IMG_ARC_PIE );
}
/* Draw an elliptical arc and fill it in */
Imagefilledarc ($ image, 50, 50,100, 50,-160, 40, $ darknavy, IMG_ARC_PIE );
Imagefilledarc ($ image, 50, 50,100, 50, 40, 75, $ darkgray, IMG_ARC_PIE );
Imagefilledarc ($ image, 50, 50,100, 50, 75,200, $ darkred, IMG_ARC_PIE );
/* Draw a string */
Imagestring ($ image, 3, 15, 55, "30%", $ white );
Imagestring ($ image, 3, 45, 35, "60%", $ white );
Imagestring ($ image, 3, 60, 60, "10%", $ white );
/* Output image */
Header ("content-type: image/png ");
Imagepng ($ image );
/* Release resources */
Imagedestroy ($ image );
?>

Effect:

2. Scale the image


Source image size


<? Php
Header ("content-type", "text/html; charset = UTF-8 ");
/*
* Image Scaling
* @ Param string $ filename url of the image
* @ Param int $ width: sets the maximum width for image scaling.
* @ Param int $ height: sets the maximum zoom height of the image.
*/
Function thumb ($ filename, $ width = 130, $ height = 130)
{
/* Obtain the size of the source image */
List ($ width_orig, $ height_orig) = getimagesize ($ filename );
/* Calculate the height and width of the proportional ratio based on the parameter $ width and $ height */
If ($ width & ($ width_orig <$ height_orig ))
{
$ Width = ($ height/$ height_orig) * $ width_orig;
}
Else
{
$ Height = ($ width/$ width_orig) * $ height_orig;
}
/* Create a canvas with a new size */
$ Image_p = imagecreatetruecolor ($ width, $ height );
/* Obtain image resources */
$ Image = imagecreatefrompng ($ filename );
/* Use imagecopyresampled scaling */
Imagecopyresampled ($ image_p, $ image, 0, 0, 0, 0, $ width, $ height, $ width_orig, $ height_orig );
/* Save the scaled image and name */
Imagepng(%image_p,'test.png ');
/* Release resources */
Imagedestroy ($ image_p );
Imagedestroy ($ image );
}
/* Call a function */
Thumb('1.png ');
?>


Scaled size

Effect:

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.