当前位置:Gxlcms > PHP教程 > php缩略图生成类(支持imagemagick与gd库)

php缩略图生成类(支持imagemagick与gd库)

时间:2021-07-01 10:21:17 帮助过:27人阅读

  1. /** 缩略图生成类,支持imagemagick及gd库两种处理

  2. * Date: 2013-07-15
  3. * Author: fdipzone
  4. * Ver: 1.2
  5. * edit: bbs.it-home.org
  6. * Func:
  7. * public set_config: 设置参数
  8. * public create_thumb: 生成缩略图
  9. * private fit: 缩略图片
  10. * private crop: 裁剪图片
  11. * private gd_fit: GD库缩略图片
  12. * private gd_crop: GD库裁剪图片
  13. * private get_size: 获取要转换的size
  14. * private get_crop_offset: 获取裁图的偏移量
  15. * private add_watermark: 添加水印
  16. * private check_handler: 判断处理程序是否已安装
  17. * private create_dirs: 创建目录
  18. * private exists: 判断参数是否存在
  19. * private to_log: 记录log
  20. * private hex2rgb: hex颜色转rgb颜色
  21. * private get_file_ext: 获取图片类型
  22. *
  23. * ver: 1.1 增加GD库处理
  24. * ver: 1.2 增加width,height错误参数处理
  25. * 增加当图片colorspace不为RGB时作转RGB处理
  26. * 修正使用crop保存为gif时出现透明无效区域问题,使用+repage参数,删除透明无效区域即可
  27. *
  28. * tips:建议使用imagemagick
  29. * GD库不支持透明度水印,如果必须使用透明水印,请将水印图片做成有透明度。
  30. * GD库输出gif如加透明水印,会有问题。
  31. */
  32. class PicThumb{ // class start
  33. private $_log = null; // log file
  34. private $_handler = null; // 进行图片处理的程序,imagemagick/gd库
  35. private $_type = 'fit'; // fit or crop
  36. private $_source = null; // 原图路径
  37. private $_dest = null; // 缩略图路径
  38. private $_watermark = null; // 水印图片
  39. private $_opacity = 75; // 水印圖片透明度,gd库不支持
  40. private $_gravity = 'SouthEast'; // 水印摆放位置 NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast
  41. private $_geometry = '+10+10'; // 水印定位,gd库不支持
  42. private $_croppos = 'TL'; // 截图的位置 TL TM TR ML MM MR BL BM BR
  43. private $_bgcolor = null; // 填充的背景色
  44. private $_quality = 90; // 生成的图片质量
  45. private $_width = null; // 指定区域宽度
  46. private $_height = null; // 指定区域高度
  47. // 初始化
  48. public function __construct($logfile=''){
  49. if($logfile!=''){
  50. $this->_log = $logfile;
  51. }
  52. }
  53. // 设置参数
  54. public function set_config($param=array()){
  55. $this->_handler = $this->exists($param, 'handler')? strtolower($param['handler']) : null;
  56. $this->_type = $this->exists($param, 'type')? strtolower($param['type']) : 'fit';
  57. $this->_watermark = $this->exists($param, 'watermark')? $param['watermark'] : null;
  58. $this->_opacity = $this->exists($param, 'opacity')? $param['opacity'] : 75;
  59. $this->_gravity = $this->exists($param, 'gravity')? $param['gravity'] : 'SouthEast';
  60. $this->_geometry = $this->exists($param, 'geometry')? $param['geometry'] : '+10+10';
  61. $this->_croppos = $this->exists($param, 'croppos')? $param['croppos'] : 'TL';
  62. $this->_bgcolor = $this->exists($param, 'bgcolor')? $param['bgcolor'] : null;
  63. $this->_quality = $this->exists($param, 'quality')? $param['quality'] : 90;
  64. $this->_width = $this->exists($param, 'width')? $param['width'] : null;
  65. $this->_height = $this->exists($param, 'height')? $param['height'] : null;
  66. }
  67. /** 创建缩略图
  68. * @param String $source 原图
  69. * @param String $dest 目标图
  70. * @return boolean
  71. */
  72. public function create_thumb($source, $dest){
  73. // 检查使用的handler是否已安装
  74. if(!$this->check_handler()){
  75. $this->to_log('handler not installed');
  76. return false;
  77. }
  78. // 判断区域宽高是否正确
  79. if(!is_numeric($this->_width) || !is_numeric($this->_height) || $this->_width<=0 || $this->_height<=0){
  80. $this->to_log('width or height invalid');
  81. return false;
  82. }
  83. // 判断源文件是否存在
  84. if(!file_exists($source)){
  85. $this->to_log($source.' not exists');
  86. return false;
  87. }
  88. // 创建目标文件路径
  89. if(!$this->create_dirs($dest)){
  90. $this->to_log(dirname($dest).' create fail');
  91. return false;
  92. }
  93. $this->_source = $source; // 源文件
  94. $this->_dest = $dest; // 目标文件
  95. // 处理图片
  96. switch($this->_type){
  97. case 'fit':
  98. if($this->_handler=='imagemagick'){
  99. return $this->fit();
  100. }else{
  101. return $this->gd_fit();
  102. }
  103. break;
  104. case 'crop':
  105. if($this->_handler=='imagemagick'){
  106. return $this->crop();
  107. }else{
  108. return $this->gd_crop();
  109. }
  110. break;
  111. default:
  112. $this->to_log($this->_type.' not fit and crop');
  113. return false;
  114. }
  115. }
  116. /** 按比例压缩或拉伸图片
  117. * @return boolean
  118. */
  119. private function fit(){
  120. // 判断是否填充背景
  121. $bgcolor = ($this->_bgcolor!=null)?
  122. sprintf(" -background '%s' -gravity center -extent '%sx%s' ", $this->_bgcolor, $this->_width, $this->_height) : "";
  123. // 判断是否要转为RGB
  124. $source_info = getimagesize($this->_source);
  125. $colorspace = (!isset($source_info['channels']) || $source_info['channels']!=3)? ' -colorspace RGB ' : '';
  126. // 命令行
  127. $cmd = sprintf("convert -resize '%sx%s' '%s' %s -quality %s %s '%s'", $this->_width, $this->_height, $this->_source, $bgcolor, $this->_quality, $colorspace, $this->_dest);
  128. // 记录执行的命令
  129. $this->to_log($cmd);
  130. // 执行命令
  131. exec($cmd);
  132. // 添加水印
  133. $this->add_watermark($this->_dest);
  134. return is_file($this->_dest)? true : false;
  135. }
  136. /** 裁剪图片
  137. * @return boolean
  138. */
  139. private function crop(){
  140. // 获取生成的图片尺寸
  141. list($pic_w, $pic_h) = $this->get_size();
  142. // 获取截图的偏移量
  143. list($offset_w, $offset_h) = $this->get_crop_offset($pic_w, $pic_h);
  144. // 判断是否要转为RGB
  145. $source_info = getimagesize($this->_source);
  146. $colorspace = (!isset($source_info['channels']) || $source_info['channels']!=3)? ' -colorspace RGB ' : '';
  147. // 命令行
  148. $cmd = sprintf("convert -resize '%sx%s' '%s' -quality %s %s -crop %sx%s+%s+%s +repage '%s'", $pic_w, $pic_h, $this->_source, $this->_quality, $colorspace, $this->_width, $this->_height, $offset_w, $offset_h, $this->_dest);
  149. // 记录执行的命令
  150. $this->to_log($cmd);
  151. // 执行命令
  152. exec($cmd);
  153. // 添加水印
  154. $this->add_watermark($this->_dest);
  155. return is_file($this->_dest)? true : false;
  156. }
  157. /** GD库按比例压缩或拉伸图片
  158. * @return boolean
  159. */
  160. private function gd_fit(){
  161. // 获取生成的图片尺寸
  162. list($pic_w, $pic_h) = $this->get_size();
  163. list($owidth, $oheight, $otype) = getimagesize($this->_source);
  164. switch($otype){
  165. case 1: $source_img = imagecreatefromgif($this->_source); break;
  166. case 2: $source_img = imagecreatefromjpeg($this->_source); break;
  167. case 3: $source_img = imagecreatefrompng($this->_source); break;
  168. default: return false;
  169. }
  170. // 按比例缩略/拉伸图片
  171. $new_img = imagecreatetruecolor($pic_w, $pic_h);
  172. imagecopyresampled($new_img, $source_img, 0, 0, 0, 0, $pic_w, $pic_h, $owidth, $oheight);
  173. // 判断是否填充背景
  174. if($this->_bgcolor!=null){
  175. $bg_img = imagecreatetruecolor($this->_width, $this->_height);
  176. $rgb = $this->hex2rgb($this->_bgcolor);
  177. $bgcolor =imagecolorallocate($bg_img, $rgb['r'], $rgb['g'], $rgb['b']);
  178. imagefill($bg_img, 0, 0, $bgcolor);
  179. imagecopy($bg_img, $new_img, (int)(($this->_width-$pic_w)/2), (int)(($this->_height-$pic_h)/2), 0, 0, $pic_w, $pic_h);
  180. $new_img = $bg_img;
  181. }
  182. // 获取目标图片的类型
  183. $dest_ext = $this->get_file_ext($this->_dest);
  184. // 生成图片
  185. switch($dest_ext){
  186. case 1: imagegif($new_img, $this->_dest, $this->_quality); break;
  187. case 2: imagejpeg($new_img, $this->_dest, $this->_quality); break;
  188. case 3: imagepng($new_img, $this->_dest, (int)(($this->_quality-1)/10)); break;
  189. }
  190. if(isset($source_img)){
  191. imagedestroy($source_img);
  192. }
  193. if(isset($new_img)){
  194. imagedestroy($new_img);
  195. }
  196. // 添加水印
  197. $this->add_watermark($this->_dest);
  198. return is_file($this->_dest)? true : false;
  199. }
  200. /** GD库裁剪图片
  201. * @return boolean
  202. */
  203. private function gd_crop(){
  204. // 获取生成的图片尺寸
  205. list($pic_w, $pic_h) = $this->get_size();
  206. // 获取截图的偏移量
  207. list($offset_w, $offset_h) = $this->get_crop_offset($pic_w, $pic_h);
  208. list($owidth, $oheight, $otype) = getimagesize($this->_source);
  209. switch($otype){
  210. case 1: $source_img = imagecreatefromgif($this->_source); break;
  211. case 2: $source_img = imagecreatefromjpeg($this->_source); break;
  212. case 3: $source_img = imagecreatefrompng($this->_source); break;
  213. default: return false;
  214. }
  215. // 按比例缩略/拉伸图片
  216. $tmp_img = imagecreatetruecolor($pic_w, $pic_h);
  217. imagecopyresampled($tmp_img, $source_img, 0, 0, 0, 0, $pic_w, $pic_h, $owidth, $oheight);
  218. // 裁剪图片
  219. $new_img = imagecreatetruecolor($this->_width, $this->_height);
  220. imagecopyresampled($new_img, $tmp_img, 0, 0, $offset_w, $offset_h, $this->_width, $this->_height, $this->_width, $this->_height);
  221. // 获取目标图片的类型
  222. $dest_ext = $this->get_file_ext($this->_dest);
  223. // 生成图片
  224. switch($dest_ext){
  225. case 1: imagegif($new_img, $this->_dest, $this->_quality); break;
  226. case 2: imagejpeg($new_img, $this->_dest, $this->_quality); break;
  227. case 3: imagepng($new_img, $this->_dest, (int)(($this->_quality-1)/10)); break;
  228. }
  229. if(isset($source_img)){
  230. imagedestroy($source_img);
  231. }
  232. if(isset($tmp_img)){
  233. imagedestroy($tmp_img);
  234. }
  235. if(isset($new_img)){
  236. imagedestroy($new_img);
  237. }
  238. // 添加水印
  239. $this->add_watermark($this->_dest);
  240. return is_file($this->_dest)? true : false;
  241. }
  242. /** 获取目标图生成的size
  243. * @return Array $width, $height
  244. */
  245. private function get_size(){
  246. list($owidth, $oheight) = getimagesize($this->_source);
  247. $width = (int)($this->_width);
  248. $height = (int)($this->_height);
  249. switch($this->_type){
  250. case 'fit':
  251. $pic_w = $width;
  252. $pic_h = (int)($pic_w*$oheight/$owidth);
  253. if($pic_h>$height){
  254. $pic_h = $height;
  255. $pic_w = (int)($pic_h*$owidth/$oheight);
  256. }
  257. break;
  258. case 'crop':
  259. if($owidth>$oheight){
  260. $pic_h = $height;
  261. $pic_w = (int)($pic_h*$owidth/$oheight);
  262. }else{
  263. $pic_w = $width;
  264. $pic_h = (int)($pic_w*$oheight/$owidth);
  265. }
  266. break;
  267. }
  268. return array($pic_w, $pic_h);
  269. }
  270. /** 获取截图的偏移量
  271. * @param int $pic_w 图宽度
  272. * @param int $pic_h 图高度
  273. * @return Array $offset_w, $offset_h
  274. */
  275. private function get_crop_offset($pic_w, $pic_h){
  276. $offset_w = 0;
  277. $offset_h = 0;
  278. switch(strtoupper($this->_croppos)){
  279. case 'TL':
  280. $offset_w = 0;
  281. $offset_h = 0;
  282. break;
  283. case 'TM':
  284. $offset_w = (int)(($pic_w-$this->_width)/2);
  285. $offset_h = 0;
  286. break;
  287. case 'TR':
  288. $offset_w = (int)($pic_w-$this->_width);
  289. $offset_h = 0;
  290. break;
  291. case 'ML':
  292. $offset_w = 0;
  293. $offset_h = (int)(($pic_h-$this->_height)/2);
  294. break;
  295. case 'MM':
  296. $offset_w = (int)(($pic_w-$this->_width)/2);
  297. $offset_h = (int)(($pic_h-$this->_height)/2);
  298. break;
  299. case 'MR':
  300. $offset_w = (int)($pic_w-$this->_width);
  301. $offset_h = (int)(($pic_h-$this->_height)/2);
  302. break;
  303. case 'BL':
  304. $offset_w = 0;
  305. $offset_h = (int)($pic_h-$this->_height);
  306. break;
  307. case 'BM':
  308. $offset_w = (int)(($pic_w-$this->_width)/2);
  309. $offset_h = (int)($pic_h-$this->_height);
  310. break;
  311. case 'BR':
  312. $offset_w = (int)($pic_w-$this->_width);
  313. $offset_h = (int)($pic_h-$this->_height);
  314. break;
  315. }
  316. return array($offset_w, $offset_h);
  317. }
  318. /** 添加水印
  319. * @param String $dest 图片路径
  320. */
  321. private function add_watermark($dest){
  322. if($this->_watermark!=null && file_exists($this->_watermark) && file_exists($dest)){
  323. list($owidth, $oheight, $otype) = getimagesize($dest);
  324. list($w, $h, $wtype) = getimagesize($this->_watermark);
  325. // 水印图比原图要小才加水印
  326. if($w<=$owidth && $h<=$oheight){
  327. if($this->_handler=='imagemagick'){ // imagemagick 添加水印
  328. $cmd = sprintf("composite -gravity %s -geometry %s -dissolve %s '%s' %s %s", $this->_gravity, $this->_geometry, $this->_opacity, $this->_watermark, $dest, $dest);
  329. $this->to_log($cmd);
  330. exec($cmd);
  331. }else{ // gd 添加水印
  332. switch($wtype){
  333. case 1: $water_img = imagecreatefromgif($this->_watermark); break;
  334. case 2: $water_img = imagecreatefromjpeg($this->_watermark); break;
  335. case 3: $water_img = imagecreatefrompng($this->_watermark); break;
  336. default: return false;
  337. }
  338. switch($otype){
  339. case 1: $dest_img = imagecreatefromgif($dest); break;
  340. case 2: $dest_img = imagecreatefromjpeg($dest); break;
  341. case 3: $dest_img = imagecreatefrompng($dest); break;
  342. default: return false;
  343. }
  344. // 水印位置
  345. switch(strtolower($this->_gravity)){
  346. case 'northwest':
  347. $posX = 0;
  348. $posY = 0;
  349. break;
  350. case 'north':
  351. $posX = ($owidth - $w) / 2;
  352. $posY = 0;
  353. break;
  354. case 'northeast':
  355. $posX = $owidth - $w;
  356. $posY = 0;
  357. break;
  358. case 'west':
  359. $posX = 0;
  360. $posY = ($oheight - $h) / 2;
  361. break;
  362. case 'center':
  363. $posX = ($owidth - $w) / 2;
  364. $posY = ($oheight - $h) / 2;
  365. break;
  366. case 'east':
  367. $posX = $owidth - $w;
  368. $posY = ($oheight - $h) / 2;
  369. break;
  370. case 'southwest':
  371. $posX = 0;
  372. $posY = $oheight - $h;
  373. break;
  374. case 'south':
  375. $posX = ($owidth - $w) / 2;
  376. $posY = $oheight - $h;
  377. break;
  378. case 'southeast':
  379. $posX = $owidth - $w;
  380. $posY = $oheight - $h;
  381. break;
  382. }
  383. imagealphablending($dest_img, true);
  384. imagecopy($dest_img, $water_img, $posX, $posY, 0, 0, $w, $h);
  385. switch($otype){
  386. case 1:imagegif($dest_img, $dest, $this->_quality); break;
  387. case 2:imagejpeg($dest_img, $dest, $this->_quality); break;
  388. case 3:imagepng($dest_img, $dest, (int)(($this->_quality-1)/10)); break;
  389. }
  390. if(isset($water_img)){
  391. imagedestroy($water_img);
  392. }
  393. if(isset($dest_img)){
  394. imagedestroy($dest_img);
  395. }
  396. }
  397. }
  398. }
  399. }
  400. /** 判断处理程序是否已安装
  401. * @return boolean
  402. */
  403. private function check_handler(){
  404. $handler = $this->_handler;
  405. if(!in_array($handler, array('imagemagick', 'gd', null))){
  406. return false;
  407. }
  408. // 检查是否有安装imagemagick
  409. $imagemagick_installed = strstr(shell_exec('convert -version'),'Version: ImageMagick')!=''? true : false;
  410. // 检查是否有安装gd库
  411. $gd_installed = function_exists('gd_info')? true : false;
  412. switch($handler){
  413. case 'imagemagick':
  414. return $imagemagick_installed;
  415. break;
  416. case 'gd':
  417. return $gd_installed;
  418. break;
  419. case null:
  420. if($imagemagick_installed){
  421. $this->_handler = 'imagemagick';
  422. return true;
  423. }
  424. if($gd_installed){
  425. $this->_handler = 'gd';
  426. return true;
  427. }
  428. break;
  429. }
  430. return false;
  431. }
  432. /** 创建图片目录
  433. * @param String $path
  434. * @return boolean
  435. */
  436. private function create_dirs($dest){
  437. if(!is_dir(dirname($dest))){
  438. return mkdir(dirname($dest), 0777, true);
  439. }
  440. return true;
  441. }
  442. /** 判断参数是否存在
  443. * @param Array $obj 数组对象
  444. * @param String $key 要查找的key
  445. * @return boolean
  446. */
  447. private function exists($obj,$key=''){
  448. if($key==''){
  449. return isset($obj) && !empty($obj);
  450. }else{
  451. $keys = explode('.',$key);
  452. for($i=0,$max=count($keys); $i<$max; $i++){
  453. if(isset($obj[$keys[$i]])){
  454. $obj = $obj[$keys[$i]];
  455. }else{
  456. return false;
  457. }
  458. }
  459. return isset($obj) && !empty($obj);
  460. }
  461. }
  462. /** 记录log
  463. * @param String $msg 要记录的log讯息
  464. */
  465. private function to_log($msg){
  466. if($this->_log){
  467. $msg = '['.date('Y-m-d H:i:s').']'.$msg."\r\n";
  468. file_put_contents($this->_log, $msg, FILE_APPEND);
  469. }
  470. }
  471. /** hex颜色转rgb颜色
  472. * @param String $color hex颜色
  473. * @return Array
  474. */
  475. private function hex2rgb($hexcolor){
  476. $color = str_replace('#', '', $hexcolor);
  477. if (strlen($color) > 3) {
  478. $rgb = array(
  479. 'r' => hexdec(substr($color, 0, 2)),
  480. 'g' => hexdec(substr($color, 2, 2)),
  481. 'b' => hexdec(substr($color, 4, 2))
  482. );
  483. } else {
  484. $r = substr($color, 0, 1) . substr($color, 0, 1);
  485. $g = substr($color, 1, 1) . substr($color, 1, 1);
  486. $b = substr($color, 2, 1) . substr($color, 2, 1);
  487. $rgb = array(
  488. 'r' => hexdec($r),
  489. 'g' => hexdec($g),
  490. 'b' => hexdec($b)
  491. );
  492. }
  493. return $rgb;
  494. }
  495. /** 获取图片类型
  496. * @param String $file 图片路径
  497. * @return int
  498. */
  499. private function get_file_ext($file){
  500. $filename = basename($file);
  501. list($name, $ext)= explode('.', $filename);
  502. $ext_type = 0;
  503. switch(strtolower($ext)){
  504. case 'jpg':
  505. case 'jpeg':
  506. $ext_type = 2;
  507. break;
  508. case 'gif':
  509. $ext_type = 1;
  510. break;
  511. case 'png':
  512. $ext_type = 3;
  513. break;
  514. }
  515. return $ext_type;
  516. }
  517. } // class end
  518. ?>
  519. demo:
  520. [php] view plaincopy
  521. define('ROOT', dirname(__FILE__));
  522. require(ROOT."/PicThumb.class.php");
  523. $logfile = ROOT.'/PicThumb.log';
  524. $source1 = ROOT.'/pic/source.jpg';
  525. $dest1 = ROOT.'/pic/1.jpg';
  526. $dest2 = ROOT.'/pic/2.gif';
  527. $dest3 = ROOT.'/pic/3.png';
  528. $source2 = ROOT.'/pic/source_cmyk.jpg';
  529. $dest4 = ROOT.'/pic/4.jpg';
  530. $dest5 = ROOT.'/pic/5.gif';
  531. $dest6 = ROOT.'/pic/6.png';
  532. $watermark = ROOT.'/pic/watermark.png';
  533. // 按比例生成缩略图
  534. $param = array(
  535. 'type' => 'fit',
  536. 'width' => 100,
  537. 'height' => 100,
  538. );
  539. $obj = new PicThumb($logfile);
  540. $obj->set_config($param);
  541. $flag = $obj->create_thumb($source1, $dest1);
  542. if($flag){ // bbs.it-home.org
  543. echo '';
  544. }else{
  545. echo 'create thumb fail';
  546. }
  547. // 按比例生成缩略图,不足部分用#FF0000填充
  548. $param = array(
  549. 'type' => 'fit',
  550. 'width' => 100,
  551. 'height' => 100,
  552. 'bgcolor' => '#FFFF00'
  553. );
  554. $obj = new PicThumb($logfile);
  555. $obj->set_config($param);
  556. $flag = $obj->create_thumb($source1, $dest2);
  557. if($flag){
  558. echo '';
  559. }else{
  560. echo 'create thumb fail';
  561. }
  562. // 裁剪250x250的缩略图,裁剪位置是底部中间,水印位置西南,透明度50
  563. $param = array(
  564. 'type' => 'crop',
  565. 'croppos' => 'BM',
  566. 'width' => 250,
  567. 'height' => 250,
  568. 'watermark' => $watermark,
  569. 'opacity' => 50,
  570. 'gravity' => 'SouthWest'
  571. );
  572. $obj = new PicThumb($logfile);
  573. $obj->set_config($param);
  574. $flag = $obj->create_thumb($source1, $dest3);
  575. if($flag){
  576. echo '';
  577. }else{
  578. echo 'create thumb fail';
  579. }
  580. // 按比例生成缩略图 CMYK格式
  581. $param = array(
  582. 'type' => 'fit',
  583. 'width' => 100,
  584. 'height' => 100,
  585. );
  586. $obj = new PicThumb($logfile);
  587. $obj->set_config($param);
  588. $flag = $obj->create_thumb($source2, $dest4);
  589. if($flag){
  590. echo '';
  591. }else{
  592. echo 'create thumb fail';
  593. }

  594. // 按比例生成缩略图,不足部分用#FF0000填充 CMYK格式

  595. $param = array(
  596. 'type' => 'fit',
  597. 'width' => 100,
  598. 'height' => 100,
  599. 'bgcolor' => '#FFFF00'
  600. );
  601. $obj = new PicThumb($logfile);
  602. $obj->set_config($param);
  603. $flag = $obj->create_thumb($source2, $dest5);
  604. if($flag){
  605. echo '';
  606. }else{
  607. echo 'create thumb fail';
  608. }
  609. // 裁剪250x250的缩略图,裁剪位置是底部中间,水印位置西南,透明度50 CMYK格式
  610. $param = array(
  611. 'type' => 'crop',
  612. 'croppos' => 'BM',
  613. 'width' => 250,
  614. 'height' => 250,
  615. 'watermark' => $watermark,
  616. 'opacity' => 50,
  617. 'gravity' => 'SouthWest'
  618. );
  619. $obj = new PicThumb($logfile);
  620. $obj->set_config($param);
  621. $flag = $obj->create_thumb($source2, $dest6);
  622. if($flag){
  623. echo '';
  624. }else{
  625. echo 'create thumb fail';
  626. }
  627. ?>

>>> php缩略图生成类源码下载地址

人气教程排行