Home > php教程 > php手册 > body text

php创建不失真高清图片实现代码

WBOY
Release: 2016-06-13 09:48:48
Original
1205 people have browsed it

在php在要生成高清的图片必须用 imagecreatetruecolor函数来做,下面看它的用法 imagecreatetruecolor(int x,int y)建立的是一幅大小为 和 y的黑色图像,它所举的例子并没用给生成的像素添加背景颜色,而是直接用imagecolorallocate()建立了一个画图的颜色

在php教程在要生成高清的图片必须用 imagecreatetruecolor函数来做,下面看它的用法

imagecreatetruecolor(int x,int y)建立的是一幅大小为 和 y的黑色图像,它所举的例子并没用给生成的像素添加背景颜色,而是直接用imagecolorallocate()建立了一个画图的颜色
*/
//创建图像
$im=imagecreatetruecolor(100,100);
//将背景设为红色
$red=imagecolorallocate($im,255,0,0);
imagefill($im,0,0,$red);
//输出图像
header('content-type: image/png');
imagepng($im);
imagedestroy($im);
/*
执行该代码,将生成背景为红色的图形。
*/

//代码二

//创建真彩色图像
$img=imagecreatetruecolor(400,400);
//通过循环执行操作
for($i=10;$i {
  //定义颜色
  $color=imagecolorallocate($img,200,50,$i);
  //画出椭圆
  imageellips教程e($img,200,200,350,$i,$color);
}
//输出图像
header("content-type: image/png");
imagepng($img);
//销毁图像
imagedestroy($img);
/*
该代码的执行结果如图:22.7所示:
*/
//代码三

//创建真彩色图像
$img=imagecreatetruecolor(200,200);
$white=imagecolorallocate($img,255,255,255);
$red=imagecolorallocate($img,255,0,0);
$blue=imagecolorallocate($img,0,0,255);
//在图像上画图
imagearc($img,100,100,50,150,360,0,$red);
imagearc($img,100,100,150,50,0,360,$blue);
//输出图像
header("content-type: image/png");
imagepng($img);
//销毁图像
imagedestroy($img);
/*
该代码的的执行结果如图22.6所示:
*/


//实例四

//发送头文件
header("content-type: image/png");
//创建图像,如果失败输出内容
$im=imagecreatetruecolor(500,500);      //创建图像
//定义背景颜色
$black=imagecolorallocate($im,0,0,0);
//定义线颜色
$color=imagecolorallocate($im,0,255,255);
//在图像上画出虚线
imageline($im,1,1,450,450,$color);
//输出图像文件
imagepng($im);
//销毁图像
imagedestroy($im);

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!