Home > Backend Development > PHP Tutorial > A brief analysis of PHP drawing technology_PHP tutorial

A brief analysis of PHP drawing technology_PHP tutorial

WBOY
Release: 2016-07-21 15:01:18
Original
817 people have browsed it

1. Image format: Common image formats currently used in website development include gif, jpg/jpeg, png....
Difference:
•gif The image compression rate is high, but it can only display 256 colors, which may cause color loss. It can display animation
•jpg/jpeg The image compression rate is high (lossy compression), and can be displayed with smaller files. Used on web pages There are more
·png. This format combines the advantages of gif and jpg. The disadvantage is that it cannot display animation

2. Drawing through PHP programming

Copy the code The code is as follows:

< ?php
//Basic steps for drawing technology: enable the gd library in the php.ini file
//The default background of the created canvas is black
$img=imagecreatetruecolor(400,300);
// Draw various graphics
//Create a color
$background = imagecolorallocate($img, 255, 0, 0);
//Draw a circle
//imageellipse($img,30,30 ,50,50,$background);
//Ellipse
//imageellipse($img,30,30,50,30,$background);
//Draw a straight line
//imageline ($img,0,0,400,300,$background);
//Draw a rectangle
//imagerectangle ($img, 50, 20, 100, 40, $background);
//Fill the rectangle
//imagefilledrectangle ($img, 50, 20, 100, 40, $background);
//Draw an arc
//imagearc($img, 100, 100, 150, 150, 180, 270, $background);
//Draw a fan-shaped IMG_ARC_CHORD straight line connecting the starting and ending points IMG_ARC_PIE
//imagefilledarc($img, 100, 100, 150, 150, 180, 270, $background,IMG_ARC_PIE);

//Copy the image to the canvas
/* $scrImg=imagecreatefromgif('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
$scrImgInfo=getimagesize(' http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
imagecopy ($img,$scrImg,10,10,0,0,$scrImgInfo[0],$scrImgInfo[1]);
*/
//imagecopy ($img,$scrImg,10,10,0,0,270,129);

//Writing
//imagestring ($img, 5, 20, 20, "hello,world", $background );
//Write Chinese
$str="PHP painting technology";
imagettftext ($img, 30, 0, 50,50, $background, "MSYHBD.TTF" , $str);
//Output the image to the web page (or save it as)
header("content-type: image/png");
imagepng($img);
//Destroy the image (release memory)
imagedestroy($img);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328023.htmlTechArticle1. Image format: Common image formats currently used in website development include gif, jpg/jpeg, png.... . Difference: GIF image compression rate is high, but it can only display 256 colors, which may cause color loss. You can...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template