php 图像 处理,PHP 处理图像步骤解析

PHP 处理图像步骤解析

发布时间:2020-05-09 16:25:55

来源:亿速云

阅读:309

作者:Leah

今天小编就为大家带来一篇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<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处理图像的方法了吗?如果想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值