Home >Backend Development >PHP Tutorial >PHP code to create high-definition images without distortion_PHP tutorial

PHP code to create high-definition images without distortion_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:45:571446browse

To generate high-definition images in PHP, you must use the imagecreatetruecolor function. Let’s see how it is used. imagecreatetruecolor(int x, int y) creates a black image of size and y. The example it gives does not add a background color to the generated pixels, but directly uses imagecolorallocate() to create a drawing color.

In the PHP tutorial, to generate high-definition images, you must use the imagecreatetruecolor function. Let’s see how it is used

imagecreatetruecolor(int x, int y) creates a black image of size and y. The example it gives does not add a background color to the generated pixels, but directly uses imagecolorallocate() to create a Color of drawing
*/
//Create image
$im=imagecreatetruecolor(100,100);
//Set the background to red
$red=imagecolorallocate($im,255,0,0);
imagefill($im,0,0,$red);
//Output image
header('content-type: image/png');
imagepng($im);
imagedestroy($im);
/*
Executing this code will generate a graphic with a red background.
*/

//Code 2

//Create true color images
$img=imagecreatetruecolor(400,400);
//Perform operations through loop
for($i=10;$i<=350;$i=$i+20)
{
//Define color
$color=imagecolorallocate($img,200,50,$i);
//Draw an ellipse
imageellips tutorial e($img,200,200,350,$i,$color);
}
//Output image
header("content-type: image/png");
imagepng($img);
//Destroy image
imagedestroy($img);
/*
The execution result of this code is shown in Figure 22.7:
*/
//Code 3

//Create true color images
$img=imagecreatetruecolor(200,200);
$white=imagecolorallocate($img,255,255,255);
$red=imagecolorallocate($img,255,0,0);
$blue=imagecolorallocate($img,0,0,255);
//Draw on the image
imagearc($img,100,100,50,150,360,0,$red);
imagearc($img,100,100,150,50,0,360,$blue);
//Output image
header("content-type: image/png");
imagepng($img);
//Destroy image
imagedestroy($img);
/*
The execution result of this code is shown in Figure 22.6:
*/


//Example 4

//Send header file
header("content-type: image/png");
//Create image, output content if failed
$im=imagecreatetruecolor(500,500); //Create image
//Define background color
$black=imagecolorallocate($im,0,0,0);
//Define line color
$color=imagecolorallocate($im,0,255,255);
//Draw a dotted line on the image
imageline($im,1,1,450,450,$color);
//Output image file
imagepng($im);
//Destroy image
imagedestroy($im);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632995.htmlTechArticleTo generate high-definition pictures in PHP, you must use the imagecreatetruecolor function. Let’s see its usage imagecreatetruecolor(int x ,int y) creates a black image with size and y,...
Statement:
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