php 图像 处理,PHP 处理图像步骤解析
一.创建图像
创建图像的一般流程:
1).设定标头,告诉浏览器你要生
今天小编就为大家带来一篇PHP中处理图像的文章。小编觉得挺不错的,为此分享给大家做个参考。一起跟随小编过来看看吧。 一.创建图像 创建图像的一般流程: 1).设定标头,告诉浏览器你要生成的MIME类型。 2).创建一个图像区域,以后的操作都将基于此图像区域。 3).在空白图像区域绘制填充背景。 4).在背景上绘制图形轮廓输入文本。 5).输出最终图形。 6).清除所有资源。 7).其他页面调用图像。 设定标头指定MIME输出类型 header('Content-Type: p_w_picpath/png'); 创建一个空白的图像区域 $im= p_w_picpathcreatetruecolor(200,200); 在空白图像区域绘制填充背景 $blue= p_w_picpathcolorallocate($im,0,102,255); p_w_picpathfill($im,0,0,$blue); 在背景上绘制图形轮廓输入文本 $white= p_w_picpathcolorallocate($im,255,255,255); p_w_picpathline($im,0,0,200,200,$white); p_w_picpathline($im,200,0,0,200,$white); p_w_picpathstring($im,5,80,20,"Mr.Lee",$white); 输出最终图形 p_w_picpathpng($im); 清除所有资源 p_w_picpathdestroy($im); 其他页面调用创建的图形 二.简单小案例 简单验证码 header('Content-type: p_w_picpath/png'); //随机数 for($Tmpa=0;$Tmpa $nmsg.=dechex(rand(0,15)); } $im= p_w_picpathcreatetruecolor(75,25); $blue= p_w_picpathcolorallocate($im,0,102,255); $white= p_w_picpathcolorallocate($im,255,255,255); p_w_picpathfill($im,0,0,$blue); p_w_picpathstring($im,5,20,4,$nmsg,$white); p_w_picpathpng($im); p_w_picpathdestroy($im); 加载已有的图像 header('Content-Type:p_w_picpath/png'); define('__DIR__',dirname(__FILE__).'\\'); $im= p_w_picpathcreatefrompng(__DIR__.'222.png'); $white= p_w_picpathcolorallocate($im,255,255,255); p_w_picpathstring($im,3,5,5,'#39;,$white); p_w_picpathpng($im); p_w_picpathdestroy($im); 加载已有的系统字体 $text= iconv("gbk","utf-8","李炎恢"); $font='C:\WINDOWS\Fonts\SIMHEI.TTF'; p_w_picpathttftext($im,20,0,30,30,$white,$font,$text); 图像微缩 header('Content-type: p_w_picpath/png'); define('__DIR__',dirname(__FILE__).'\\'); list($width,$height) = getp_w_picpathsize(__DIR__.'222.png'); $new_width=$width*0.7; $new_height=$height*0.7; $im2= p_w_picpathcreatetruecolor($new_width,$new_height); $im= p_w_picpathcreatefrompng(__DIR__.'222.png'); p_w_picpathcopyresampled($im2,$im,0,0,0,0, $new_width,$new_height,$width,$height); p_w_picpathpng($im2); p_w_picpathdestroy($im); Imagedestroy($im2); 看完上诉内容,你们掌握PHP处理图像的方法了吗?如果想了解更多相关内容PHP图像处理,欢迎关注亿速云行业资讯频道,感谢各位的阅读! (编辑:成都站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |