学习矢量图片(验证码),报表的绘制,生成。希望本文能帮助到大家。
创建画布 会只需要的各种图形(圆,直线,矩形,弧线,扇形) 输出图像到网页,也可以另存 销毁图片(释放内存)
gif 图片压缩率高, 但是只能显示256色可能造成颜色丢失,但可以显示动画 jpg/jpeg 图片的压缩率高,可以用较小的文件来显示 网页上用的比较多 png,高仿真 综合了gif和jpg的优势,但是不能显示动画
创建画布$img = imagecreatetruecolor(100,100);
取色$red = imagecolorallocate($img, 255, 0, 0);
画图
•imagefilledarc — 画一椭圆弧且填充
•imagefilledellipse — 画一椭圆并填充
•imagefilledpolygon — 画一多边形并填充
•imagefilledrectangle — 画一矩形并填充
输出到浏览器header("content-type: image/png");
imagepng($img);
销毁
imagedestroy($img);$srcImage = imagecreatefromgif(filename);$srcImage_info = getimagesize(filename);
imagecopy(dst_im, src_im, dst_x, dst_y,
src_x, src_y, src_w, src_h);
具体参数含义 不懂看文档imagettftext(image, size, angle, x, y,
color, fontfile, text)<?php /**
* Created by PhpStorm.
* User: draymonder
* Date: 2018/3/1
* Time: 15:15
*/
$checkcode =""; for($i=0;$i<4;$i++){ $checkcode.= dechex(rand(0,15));
} $img = imagecreatetruecolor(200,30); //背景颜色
$bgcolor = imagecolorallocate($img,0,0,0);
imagefill($img,0,0,$bgcolor); //添加干扰线
for($i=0;$i<10;$i++){ $color = imagecolorallocate($img,rand(0,255),rand(0,255),rand(0,255));
imageline($img,rand(0,200),rand(0,30),rand(0,200),rand(0,30),$color);
} //白色,字体颜色
$white = imagecolorallocate($img,255,255,255); //添加字符串
imagestring($img,rand(4,6),rand(0,180),rand(0,20),$checkcode,$white);
header("content-type: image/png");
imagepng($img);
imagedestroy($img);
?>相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是PHP绘图技术实例讲解的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号