php创建不失真高清图片实现代码
在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);

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
