PHP to make 3D sector statistics and zoom operation Example _php instance

Source: Internet
Author: User
Tags 0xc0

1, the use of PHP functions of the GD library to draw 3D sector statistics

<?php
Header ("Content-type", "text/html;charset=utf-8");
/* Sector Chart * *
$image = Imagecreatetruecolor (100, 100); /* Create 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 Background color * *
Imagefill ($image, 0, 0, $white);
/*3d Making * *
for ($i = $i > $i-)
{
Imagefilledarc ($image, $i, M, -160, $darknavy, Img_arc_pie);
Imagefilledarc ($image, $i, M, N, $darkgray, Img_arc_pie);
Imagefilledarc ($image, $i, M, N, $darkred, Img_arc_pie);
}
/* Draw ellipse arc and fill/*
Imagefilledarc ($image, M, -160, $darknavy, Img_arc_pie);
Imagefilledarc ($image, $darkgray, M, Img_arc_pie);;
Imagefilledarc ($image, N, $darkred, Img_arc_pie), and
/* Draw String * *
Imagestring ($image, 3,,, "30%", $white);
Imagestring ($image, 3, A, "60%", $white);
Imagestring ($image, 3,,, "10%", $white);
/* Output Image * *
Header ("Content-type:image/png");
Imagepng ($image);
/* Release of resources * *
Imagedestroy ($image);
?>

Effect:

2, zoom to the picture

<div>

</div>
<?php
Header ("Content-type", "text/html;charset=utf-8");
/*
* Picture Scaling
* @param string $filename The URL of the picture
* @param int $width Set the maximum width of picture scaling
* @param int $height Set the maximum height of picture scaling
*/
function Thumb ($filename, $width =130, $height =130)
{
/* Get the size of the original * *
List ($width _orig, $height _orig) = getimagesize ($filename);
/* According to the parameters $width and $height, the conversion of equal proportions of the height and width * *
if ($width && ($width _orig < $height _orig))
{
$width = ($height/$height _orig) * $width _orig;
}
Else
{
$height = ($width/$width _orig) * $height _orig;
}
/* Create canvas with new size * *
$image _p = Imagecreatetruecolor ($width, $height);
/* Get Image resources * *
$image = Imagecreatefrompng ($filename);
/* Use imagecopyresampled Zoom * *
Imagecopyresampled ($image _p, $image, 0, 0, 0, 0, $width, $height, $width _orig, $height _orig);
/* Save scaled Picture and name * *
Imagepng ($image _p, ' test.png ');
/* Release of resources * *
Imagedestroy ($image _p);
Imagedestroy ($image);
}
/* Call Function * *
Thumb (' 1.png ');
?>
<div>

</div>

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.