]> 4ch.mooo.com Git - test.git/blob - lib/thumb/thumb.repng2jpeg.php
d6414588fd2c585e0e34759c42c3e7670f49ea1e
[test.git] / lib / thumb / thumb.repng2jpeg.php
1 <?php\r
2 /**\r
3  * Thumbnail Generate API: Imagick Wrapper\r
4  *\r
5  * 提供程式便於以 repng2jpeg 生成預覽圖的物件\r
6  *\r
7  * @package PMCLibrary\r
8  * @version $Id: thumb.repng2jpeg.php 497 2007-08-05 12:39:26Z scribe $\r
9  * @date $Date: 2007-08-05 20:39:26 +0800 (星期日, 05 八月 2007) $\r
10  */\r
11 \r
12 class ThumbWrapper{\r
13         var $sourceFile, $sourceWidth, $sourceHeight, $thumbWidth, $thumbHeight, $thumbQuality;\r
14         var $_exec;\r
15 \r
16         function ThumbWrapper($sourceFile='', $sourceWidth=0, $sourceHeight=0){\r
17                 $this->sourceFile = $sourceFile;\r
18                 $this->sourceWidth = $sourceWidth;\r
19                 $this->sourceHeight = $sourceHeight;\r
20                 $this->_exec = realpath('./repng2jpeg'.(strtoupper(substr(PHP_OS, 0, 3))==='WIN' ? '.exe' : ''));\r
21         }\r
22 \r
23         function getClass(){\r
24                 $str = 'repng2jpeg Wrapper';\r
25                 if($this->isWorking()){\r
26                         $str .= ' : '.`$this->_exec --version`;\r
27                 }\r
28                 return $str;\r
29         }\r
30 \r
31         function isWorking(){\r
32                 return file_exists($this->_exec) && function_exists('exec') && (strtoupper(substr(PHP_OS, 0, 3))==='WIN' || is_executable($this->_exec));\r
33         }\r
34 \r
35         function setThumbnailConfig($thumbWidth, $thumbHeight, $thumbQuality=50){\r
36                 $this->thumbWidth = $thumbWidth;\r
37                 $this->thumbHeight = $thumbHeight;\r
38                 $this->thumbQuality = $thumbQuality;\r
39         }\r
40 \r
41         function makeThumbnailtoFile($destFile){\r
42                 if(!$this->isWorking()) return false;\r
43                 switch(strtolower(strrchr($this->sourceFile, '.'))){ // 取出副檔名\r
44                         case '.jpg':\r
45                         case '.gif':\r
46                         case '.png':\r
47                                 break; // 僅支援此三種格式\r
48                         default:\r
49                                 return false;\r
50                 }\r
51                 $CLI = "$this->_exec \"$this->sourceFile\" \"$destFile\" $this->thumbWidth $this->thumbHeight $this->thumbQuality";\r
52                 @exec($CLI);\r
53                 return true;\r
54         }\r
55 }\r
56 ?>