ThinkPHP 圖片處理函數,需要文字水印字體,可在windows下 控制面板 > 大圖標(右上角) > 字體 找到需要的字體.
- /**
- * 圖像的裁剪、縮放、加水印
- * @param string $path 路徑
- * @param int $width 裁剪的寬度/限制的高度或寬度,當有$height值時此值為圖片的寬度,否則為限制的寬度或高度
- * @param int $height [可選]裁剪的高度
- * @param boolean $water [可選]是否加水印
- * @param int $word [可選]水印文字
- */
- functionzoom_image($path,$width= 300,$height= null,$water= null,$word='water'){
- $image=new/Think/Image();
- $image->open($path);
- $imgWidth=$image->width();
- $imgHeight=$image->height();
- // 限制尺寸
- if($widthand!$height){
- $maxSize=$width;
- // 寬度或高度大于規定尺寸時
- if($imgWidth>$maxSizeor$imgHeight>$maxSize){
- $size= image_min_width($imgWidth,$imgHeight,$maxSize);
- $image->thumb($size['width'],$size['height']);
- $do= true;
- $dowater= true;
- }
- // 裁剪固定尺寸
- }elseif($widthand$height){
- $size= image_min_width($imgWidth,$imgHeight,$width);
- $image->thumb($size['width'],$size['height'])->crop($width,$height);
- $do= true;
- $dowater= true;
- } //Vevb.com
- if($dowaterand$waterand$word){
- $image->text($word,'./Public/images/arial.ttf',20,'#dddddd', /Think/Image::IMAGE_WATER_SOUTHEAST,-10);
- }
- // 未操作則不保存
- if($do){
- $image->save($path);
- }
- }
新聞熱點
疑難解答
圖片精選