本文实例讲述了thinkphp框架实现图像裁剪、缩放、加水印的方法。分享给大家供大家参考,具体如下:
thinkphp 图片处理函数,需要文字水印字体,可在windows下 控制面板 > 大图标(右上角) > 字体 找到需要的字体
/**
* 图像的裁剪、缩放、加水印
* @param string $path 路径
* @param int $width 裁剪的宽度/限制的高度或宽度,当有$height值时此值为图片的宽度,否则为限制的宽度或高度
* @param int $height [可选]裁剪的高度
* @param boolean $water [可选]是否加水印
* @param int $word [可选]水印文字
*/
function zoom_image($path,$width = 300,$height = null,$water = null,$word = 'water'){
$image = new thinkimage();
$image->open($path);
$imgwidth = $image->width();
$imgheight = $image->height();
// 限制尺寸
if($width and !$height){
$maxsize = $width;
// 宽度或高度大于规定尺寸时
if($imgwidth > $maxsize or $imgheight > $maxsize){
$size = image_min_width($imgwidth,$imgheight,$maxsize);
$image->thumb($size['width'], $size['height']);
$do = true;
$dowater = true;
}
// 裁剪固定尺寸
}else if($width and $height){
$size = image_min_width($imgwidth,$imgheight,$width);
$image->thumb($size['width'], $size['height'])->crop($width, $height);
$do = true;
$dowater = true;
}
if($dowater and $water and $word){
$image->text($word,'./public/images/arial.ttf',20,'#dddddd', thinkimage::image_water_southeast,-10);
}
// 未操作则不保存
if($do){
$image->save($path);
}
}
ps:这里再为大家推荐几款比较实用的图片处理工具供大家参考使用:
在线图片转换base64工具:
http://tools.jb51.net/transcoding/img2base64
ico图标在线生成工具:
http://tools.jb51.net/aideddesign/ico_img
在线email邮箱图标制作工具:
http://tools.jb51.net/email/emaillogo
在线图片格式转换(jpg/bmp/gif/png)工具:
http://tools.jb51.net/aideddesign/picext
更多关于thinkphp相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》、《thinkphp模板操作技巧总结》、《thinkphp常用方法总结》、《codeigniter入门教程》、《ci(codeigniter)框架进阶教程》、《zend framework框架入门教程》、《smarty模板入门基础教程》及《php模板技术总结》。
希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!