php+图像处理实例,php图像处理常用函数与实例

PHP开发学习中,经常会使用到处理图形和图像:下面我们来归纳几个常用的图像函数

1. imagecreatetruecolor()  新建一个真彩色图像

resource imagecreatetruecolor ( int x_size, int y_size )

imagecreatetruecolor() 返回一个图像标识符,代表了一幅大小为 x_size 和 y_size 的黑色图像。

2. imagecolorallocate()  为一幅图像分配颜色

int imagecolorallocate ( resource image, int red, int green, int blue )

imagecolorallocate() 返回一个标识符,代表了由给定的 RGB 成分组成的颜色。red,green 和 blue 分别是所需要的颜色的红,绿,蓝成分。

3. imagefill()  区域填充

bool imagefill ( resource image, int x, int y, int color )

imagefill() 在 image 图像的坐标 x,y(图像左上角为 0, 0)处用 color 颜色执行区域填充(即与 x, y 点颜色相同且相邻的点都会被填充)。

4. imagestring()  水平地画一行字符串

bool imagestring ( resource image, int font, int x, int y, string s, int col )

imagestring() 用 col 颜色将字符串 s 画到 image 所代表的图像的 x,y 坐标处(这是字符串左上角坐标,整幅图像的左上角为 0,0)。如果 font 是 1,2,3,4 或 5,则使用内置字体。

5. imageline()  画一条线段

bool imageline ( resource image, int x1, int y1, int x2, int y2, int color )

imageline() 用 color 颜色在图像 image 中从坐标 x1,y1 到 x2,y2(图像左上角为 0, 0)画一条线段。

6. imagesetpixel()  画一个单一像素

bool imagesetpixel ( resource image, int x, int y, int color )

imagesetpixel() 在 image 图像中用 color 颜色在 x,y 坐标(图像左上角为 0,0)上画一个点。

7. imagettftext()  用 TrueType 字体向图像写入文本

array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )

image 图像资源

size 字体大小

angle 角度制表示的角度,0 度为从左向右读的文本。更高数值表示逆时针旋转

x 由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)

y Y 坐标。它设定了字体基线的位置,不是字符的最底端

color 颜色索引。使用负的颜色索引值具有关闭防锯齿的效果

fontfile 是想要使用的 TrueType 字体的路径。

text 要写入的文本字符串

8. imagecreatefrompng()  从 PNG 文件或 URL 新建一图像

resource imagecreatefrompng ( string filename )

imagecreatefrompng() 返回一图像标识符,代表了从给定的文件名取得的图像。

9. imagecopyresampled()  重采样拷贝部分图像并调整大小

bool imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )

imagecopyresampled() 将一幅图像中的一块正方形区域拷贝到另一个图像中,平滑地插入像素值,因此,尤其是,减小了图像的大小而仍然保持了极大的清晰度。如果成功则返回 TRUE,失败则返回 FALSE。

10. PHP生成简单的邮件图标代码

header('Content-Type:image/png');

$img=imagecreatetruecolor(400,200);

$blue=imagecolorallocate($img,0,102,255);

$white=imagecolorallocate($img,255,255,255);

imagefill($img,0,0,$blue);

imagestring($img,2,130,50,'Emailto:admin@TTinfo.com',$white);

imageline($img,0,0,400,200,$white);

imageline($img,0,200,400,0,$white);

for($i=0;$i<200;$i++){

imagesetpixel($img,rand(0,400),rand(0,200),$white);

}

$font='C:\WINDOWS\Fonts\SIMKAI.TTF';

$text=iconv('utf-8','utf-8','收件人:管理员');

imagettftext($img,20,0,108,40,$white,$font,$text);

imagepng($img);

imagedestroy($img);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值