thinkPHP框架實現(xiàn)圖像裁剪、縮放、加水印的方法
本文實例講述了thinkPHP框架實現(xiàn)圖像裁剪、縮放、加水印的方法。分享給大家供大家參考,具體如下:
ThinkPHP 圖片處理函數(shù),需要文字水印字體,可在windows下 控制面板 > 大圖標(右上角) > 字體 找到需要的字體
/**
* 圖像的裁剪、縮放、加水印
* @param string $path 路徑
* @param int $width 裁剪的寬度/限制的高度或?qū)挾?,當?height值時此值為圖片的寬度,否則為限制的寬度或高度
* @param int $height [可選]裁剪的高度
* @param boolean $water [可選]是否加水印
* @param int $word [可選]水印文字
*/
function zoom_image($path,$width = 300,$height = null,$water = null,$word = 'water'){
$image = new \Think\Image();
$image->open($path);
$imgWidth = $image->width();
$imgHeight = $image->height();
// 限制尺寸
if($width and !$height){
$maxSize = $width;
// 寬度或高度大于規(guī)定尺寸時
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', \Think\Image::IMAGE_WATER_SOUTHEAST,-10);
}
// 未操作則不保存
if($do){
$image->save($path);
}
}
PS:這里再為大家推薦幾款比較實用的圖片處理工具供大家參考使用:
在線圖片轉(zhuǎn)換BASE64工具:
http://tools.jb51.net/transcoding/img2base64
ICO圖標在線生成工具:
http://tools.jb51.net/aideddesign/ico_img
在線Email郵箱圖標制作工具:
http://tools.jb51.net/email/emaillogo
在線圖片格式轉(zhuǎn)換(jpg/bmp/gif/png)工具:
http://tools.jb51.net/aideddesign/picext
更多關于thinkPHP相關內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎教程》及《PHP模板技術總結》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。
相關文章
基于curl數(shù)據(jù)采集之正則處理函數(shù)get_matches的使用
本篇文章介紹了,基于curl數(shù)據(jù)采集之正則處理函數(shù)get_matches的使用。需要的朋友參考下2013-04-04
ThinkPHP3.2.3框架Memcache緩存使用方法實例總結
這篇文章主要介紹了ThinkPHP3.2.3框架Memcache緩存使用方法,結合實例形式總結分析看thinkPHP框架下Memcache緩存各種調(diào)用方法與配置相關操作技巧,需要的朋友可以參考下2019-04-04
destoon文章模塊調(diào)用企業(yè)會員資料的方法
這篇文章主要介紹了destoon文章模塊調(diào)用企業(yè)會員資料的方法,非常實用的一個技巧,需要的朋友可以參考下2014-08-08

