thinkPHP框架实现图像裁剪、缩放、加水印的方法 本文实例讲述了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 \Think\Image(); $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', \Think\Image::IMAGE_WATER_SOUTHEAST,-10); } // 未操作则不保存 if($do){ $image->save($path); } } PS:这里再为大家推荐几款比较实用的图片处理工具供大家参考使用: 在线图片转换BASE64工具: http://tools.zwyuanma.com/transcoding/img2base64 ICO图标在线生成工具: http://tools.zwyuanma.com/aideddesign/ico_img 在线Email邮箱图标制作工具: http://tools.zwyuanma.com/email/emaillogo 在线图片格式转换(jpg/bmp/gif/png)工具: http://tools.zwyuanma.com/aideddesign/picext 更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》、《smarty模板入门基础教程》及《PHP模板技术总结》。 希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。