成都创新互联网站制作重庆分公司

PHP处理图像步骤解析

今天小编就为大家带来一篇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);

?>

 

其他页面调用创建的图形

"Demo4.php" alt="PHP创建的图片"/>

 

 

二.简单小案例

 

简单验证码

header('Content-type: p_w_picpath/png');

//随机数

for($Tmpa=0;$Tmpa<4;$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,'http://www.yc60.com',$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处理图像步骤解析
转载源于:http://cxhlcq.com/article/pooccc.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部