]> 4ch.mooo.com Git - test.git/blobdiff - lib/thumb/thumb.repng2jpeg.php
modified: .gitignore
[test.git] / lib / thumb / thumb.repng2jpeg.php
diff --git a/lib/thumb/thumb.repng2jpeg.php b/lib/thumb/thumb.repng2jpeg.php
new file mode 100755 (executable)
index 0000000..d641458
--- /dev/null
@@ -0,0 +1,56 @@
+<?php\r
+/**\r
+ * Thumbnail Generate API: Imagick Wrapper\r
+ *\r
+ * 提供程式便於以 repng2jpeg 生成預覽圖的物件\r
+ *\r
+ * @package PMCLibrary\r
+ * @version $Id: thumb.repng2jpeg.php 497 2007-08-05 12:39:26Z scribe $\r
+ * @date $Date: 2007-08-05 20:39:26 +0800 (星期日, 05 八月 2007) $\r
+ */\r
+\r
+class ThumbWrapper{\r
+       var $sourceFile, $sourceWidth, $sourceHeight, $thumbWidth, $thumbHeight, $thumbQuality;\r
+       var $_exec;\r
+\r
+       function ThumbWrapper($sourceFile='', $sourceWidth=0, $sourceHeight=0){\r
+               $this->sourceFile = $sourceFile;\r
+               $this->sourceWidth = $sourceWidth;\r
+               $this->sourceHeight = $sourceHeight;\r
+               $this->_exec = realpath('./repng2jpeg'.(strtoupper(substr(PHP_OS, 0, 3))==='WIN' ? '.exe' : ''));\r
+       }\r
+\r
+       function getClass(){\r
+               $str = 'repng2jpeg Wrapper';\r
+               if($this->isWorking()){\r
+                       $str .= ' : '.`$this->_exec --version`;\r
+               }\r
+               return $str;\r
+       }\r
+\r
+       function isWorking(){\r
+               return file_exists($this->_exec) && function_exists('exec') && (strtoupper(substr(PHP_OS, 0, 3))==='WIN' || is_executable($this->_exec));\r
+       }\r
+\r
+       function setThumbnailConfig($thumbWidth, $thumbHeight, $thumbQuality=50){\r
+               $this->thumbWidth = $thumbWidth;\r
+               $this->thumbHeight = $thumbHeight;\r
+               $this->thumbQuality = $thumbQuality;\r
+       }\r
+\r
+       function makeThumbnailtoFile($destFile){\r
+               if(!$this->isWorking()) return false;\r
+               switch(strtolower(strrchr($this->sourceFile, '.'))){ // 取出副檔名\r
+                       case '.jpg':\r
+                       case '.gif':\r
+                       case '.png':\r
+                               break; // 僅支援此三種格式\r
+                       default:\r
+                               return false;\r
+               }\r
+               $CLI = "$this->_exec \"$this->sourceFile\" \"$destFile\" $this->thumbWidth $this->thumbHeight $this->thumbQuality";\r
+               @exec($CLI);\r
+               return true;\r
+       }\r
+}\r
+?>
\ No newline at end of file