有关图形处理的一些函数:http://www.runoob.com/php/php-image-gd.html
图形的一些操作:要创建一个画布,然后再进行其他操作
<?php
header("Content-type:text/html;charset=utf-8");
header("Content-type:image/png");//设置图像输出流一般可以为png,jpg,gif,bmp
$ima=imagecreatetruecolor(500,500);//创建一个图像区域,返回的是资源句柄
//imagecolorallocate($ima,255,0,0);//设置为红色
//imagecolorallocate($ima,0,102,0);//设置为绿色
$blue=imagecolorallocate($ima,0,102,255);//设置为蓝色
imagefill($ima,0,0,$blue);//将背景填充为蓝色
$white=imagecolorallocate($ima,255,0,0);
imageline($ima,0,0,500,500,$white);//添加线条,还有其他函数来创建其他图形,例:inagearc(图形,椭圆中心x坐标,椭圆中心y坐标,椭圆宽度,椭圆高度,起始点,角度,颜色)创建椭圆弧
imageline($ima,500,0,0,500,$white);
imagestring($ima,5,200,100,"picture",$white);//在图片上添加文字
imagepng($ima);//输出图形
imagedestroy($ima);//销毁图片
?>
将一个图片缩放而不因为裁剪失去图形的内容
<?php
//微缩图
define('picture',dirname(__FILE__).'\\');//定义一个常量,将引入的图片的路径定义为picture
header('Content-type:image/jpeg');//因为我引入的是jpg文件,所以这里的header里写的是jpeg,后面的一些函数也是利用的jpeg
list($chang,$gao)=getimagesize(picture.'yan.jpg');//将图片的长和宽引入
//将原图缩放
$_chang=$chang*0.5;
$_gao=$gao*0.5;
//创建新的图
$ima=imagecreatetruecolor($_chang,$_gao);
$im=imagecreatefromjpeg(picture.'yan.jpg');//将图片引入
imagecopyresampled($ima,$im,0,0,0,0,$_chang,$_gao,$chang,$gao);//将图片的长和宽缩放
imagejpeg($ima,null,100/*清晰度*/);//设置图片清晰度,若为png的图片就不需要了,因为png的清晰度最高
imagedestroy($ima);
imagedestroy($im);
?>