php扩展之画图

<?php
//print_r(gd_info());//取得当前安装的 GD 库的信息
创建画布
/*$im=imagecreatetruecolor(300, 200);
//创建颜料
$gray=imagecolorallocate($im, 100,100,100);
//然后是画,,也可以是填充,
imagefill($im, 100, 100, $gray);
//保存成png图片
$a=imagepng($im,'./01.png')
//销毁
imagedestroy($a);
*/
//创建画布(要造什么格式的画布)
/*$im=imagecreatefromjpeg('./home.jpg');
//然后是造颜料,两种颜料,因为一个函数只能一种,所以两种,开始
$red=imagecolorallocate($im, 255,0,0);
$blue=imagecolorallocate($im, 0,0,255);
//然后是画线
imageline($im, 0,0,670,503,$red)
//然后是不知道
header('content-type:image/jpeg')
//header("Content-type: image/jpeg")表明请求页面的内容是jpeg格式的图像。 
//然后是输出把
imagejpeg($im);//输出的是jpeg的图片呀,只有jpeg的图片才能输出呀
//销毁
imagedestroy($im);
*/
//创建一个jpg格式的画布,名字叫做home
/*$im=imagecreatefromjpeg('./home.jpg');
//然后是颜料
$blue=imagecolorallocate($im,0,0,255);
//ttf字体库。
imagettftext($im, 50, 0, 100, 100, $blue, './msyh.ttf',"宋体");
header('Content-type:image/jpeg');
//然后是输出jpeg的画布
imagejpeg($im);
imagedestroy($im);
*/
//创建画布,400*400,宽*高
/*$im=imagecreatetruecolor(400, 400);
//然后是颜料
$gray=imagecolorallocate($im,100,100,100);
$blue=imagecolorallocate($im, 0,0,255);
//然后是填充
imagefill($im, 0,0,$gray)
//然后是
imagearc($im,300,300,300,300, 45, 135, $blue);
header('Content-type:image/jpeg');
///然后输出
imagejpeg($im);*/
//是椭圆
//创建画布400*800
/*$im=imagecreatetruecolor(400, 800);
//颜料100100100
$gray=imagecolorallocate($im, 100,100,100);
//颜料00255
$blue=imagecolorallocate($im, 0,0,255);
//然后是填充
imagefill($im,0,0,$gray)
//然后是画椭圆
imageellipse($im, 200,50,200,100, $blue);
//然后是画矩形
imagerectangle($im,100,100,300,200,$blue);
*/
//画一个圆弧
//创建画布
/*$im=imagecreatetruecolor(500,500);
//然后是做颜料
$gray=imagecolorallocate($im,100,100,100);
$blue=imagecolorallocate($im,0,0,255);
//然后是填充
imagefill($im, 0,0, $gray);
//然后是画椭圆弧
imagearc($im, 200,200,200,200,45,135,$blue);
///然后是设置gd类型
header('content-type:image/jpeg')
//输出jpeg图片
imagejpeg($im);
*/
//画矩=矩形
//查创建画布
/*$im=imagecreatetruecolor(400, 800);
//然后是颜料,一种是蓝色,一种是gray色,
$gray=imagecolorallocate($im, 100,100,100);
$blue=imagecolorallocate($im, 0,0,255);
//然后是填充
imagefill($im, 0,0, $gray)
//然后是画椭圆
imageellipse($im, 200,50,200,100,$blue);
//然后是画矩形
imagerectangle($im, 100,100,300,200,$blue);
imageellipse($im, 200,300,200,200,$blue)
//然后是输出销毁类型
header('content-type:image/jpeg');
imagejpeg($im);
imagedestroy($im);
*/
/*$im=imagecreatetruecolor(400, 400);
//然后是颜料4种
$gray=imagecolorallocate($im,100,100,100);
$blue=imagecolorallocate($im,0,0,255);
$red=imagecolorallocate($im, 255,0,0);
$orange=imagecolorallocate($im,248,224,143);
//然后是把颜色填充到画布上
imagefill($im, 100,100,$gray);
//然后是画椭圆
imageellipse($im,200,200,200,200,$blue);
//然后是填充椭圆
imagefill($im, 200,200,$red);
//然后是画一个矩形直接填充
imagefilledrectangle($im, 0,100,200,200,$blue);
imagefilledellipse($im,100,80,200,100,$orange);
header('content-type:image/jpeg');
imagejpeg($im);
imagedestroy($im);
*/
//读取图片作为画布资源,就是说要
/*$small=imagecreatefrompng('./feng.png');//这个小图
//然后是判断大小
$cx=imagesx($small);//小图的宽
$cy=imagesy($small);//小图的高
//然后是两倍大画布资源
$big=imagecreate(2*$cx, 2*$cy);
//然后是设置画布的背景为100,100,100
$gray=imagecolorallocate($big, 100,100,100);
//然后是铺上大布上
imagefill($big,0,0,$gray);
*/
//验证码

/*function randName($n = 6) {
        if($n <= 0) {
            return '';
        }
        $str = 'abcdefghijkmnpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ0123456789';
        $str = substr(str_shuffle($str),0,$n);

        return $str;
    }

// 做验证码

$im = imagecreatetruecolor(80,30);

$gray = imagecolorallocate($im,30,30,30);
$red = imagecolorallocate($im,255,0,0);

imagefill($im,0,0,$gray);

imagestring($im,5,5,5,randName(4),$red);

// 输出
header('content-type: image/jpeg');
imagejpeg($im);
*/
//缩略图:意思是在一张大画布上创建一个小画布粘贴上去大画布上
//先创建获取一个png格式的图片,,,图片名叫做feng.png
/*$feng=imagecreatefrompng('./feng.png');
//然后是获取这张图片的宽高
$fx=imagesx($feng);//获取宽
$fy=imagesy($feng);//获取高
//然后是做一个1/2的小画布,,并创建出来宽额和高
$sx=$fx/2;//$sx小画布
$sy=$fy/2;//$xy小画布
//然后是先创建出小画布
$small=imagecreatetruecolor($sx, $sy);
//然后是imagecopyresampled
/*imagecopyresampled是 返回更改过的图像
也就是第一个是新创建的图片的,第二个是什么格式的图片的image
*/
/*imagecopyresampled($small, $feng, 0,0,0,0, $fx,$fy,$sx,$sy);
//作用是两张图片
//然后是判断如果
if(imagepng($small,'./xiaofeng.png'))//意思是small这张画布在不在路径当前路径下
{
	echo "成功";
}
else
{
	echo "失败";
}*/
//然后销毁*/
//造大图画布
/*$big=imagecreatetruecolor(2*$sx, 2*sy);
//然后是颜料
$gray=imagecolorallocate($big,100,100,100);
//然后是把1颜料进大画布里面
imagefill($big, 0,0, $gray);
//复制小图到大图上
imagecopy($big, $small, 0,0,0,0,$sx,$sy);
//然后设置字符集
header('content-type:image/jpeg');
//然后是输出了
imagejpeg($big);
//然后销毁
imagedestroy($small)
*/
//然后是水印效果
/*$big=imagecreatefromjpeg('./home.jpg');//意思是创建格式为jpg名字为home在当前路径下的画布
//然后是获取这张画布的xy宽高
$bx=imagesx($big);
$by=imagesy($big);
//然后是在创建
$small=imagecreatefrompng('./feng.png');
//然后是算出它的大小
$sx=imagesx($small);
$sy=imagesy($small)
//然后是加文字
$blue=imagecolorallocate($big,0,0,255);
//然后是加文字
imagettftext($big, 16,0,100,100,$blue,'./msyh.ttf','陈业贵爱李文');
//然后是imagecopymerge函数用于拷贝并合并图像的一部分,成功返回 TRUE ,否则返回 FALSE 。
imagecopymerge($big, 16,0,100,100,$blue,'./msth.ttf','陈业贵爱李文');
//然后是字符集
header('content-type:image/jpeg');
imagejpeg($big);
imagedestroy($big);
*/
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

贵哥的编程之路(热爱分享)

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值