-<?php\r
-\r
-class NP_ImageCreateThumbnail extends NucleusPlugin {\r
-\r
- /* \r
- * Nucleus Plugin\r
- *\r
- * Copyright 2007 by Kai Greve\r
- * \r
- * This program is free software and open source software; you can redistribute\r
- * it and/or modify it under the terms of the GNU General Public License as\r
- * published by the Free Software Foundation; either version 2 of the License,\r
- * or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful, but WITHOUT\r
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
- * more details.\r
- *\r
- * You should have received a copy of the GNU General Public License along\r
- * with this program; if not, write to the Free Software Foundation, Inc.,\r
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit\r
- * http://www.gnu.org/licenses/gpl.html\r
- * \r
- *\r
- * NP_ImageCreateThumbnail creates a thumbnail after an image is uploaded,\r
- * it demonstrates the uages of the PostMediaUpload event \r
- *\r
- * History:\r
- * v0.01: 2007-01-01\r
- * - initial release \r
- * \r
- */\r
-\r
- function getName() { return 'NP_ImageCreateThumbnail'; }\r
- function getAuthor() { return 'Kai Greve'; }\r
- function getURL() { return 'http://www.nucleuscms.org/'; }\r
- function getVersion() { return '0.01'; }\r
- function getDescription() { return 'Generates Thumbnails after an image is uploaded.'; }\r
- \r
- function getMinNucleusVersion() { return 330; }\r
-\r
- function supportsFeature($what) {\r
- switch($what)\r
- { case 'SqlTablePrefix':\r
- return 1;\r
- default:\r
- return 0; }\r
- }\r
-\r
- function install() {\r
- $this->createOption ('thumbsize', 'Maximal width (landscape format) or height (portrait format) for Thumbnails', 'text', '150');\r
- }\r
-\r
- function unInstall() {\r
- }\r
-\r
- function getEventList() {\r
- return array('PostMediaUpload');\r
- }\r
-\r
-\r
- function event_PostMediaUpload(&$data) {\r
- \r
- $collection = $data['collection'];\r
- $mediadir = $data['mediadir'];\r
- $filename = $data['filename'];\r
- $fullpath = $mediadir.$filename;\r
- \r
- // evaluate the filetype from the filename\r
- $filetype = strtolower(substr($filename, strpos($filename, ".")+1));\r
- \r
- // filetype is jpeg\r
- if ($filetype=='jpg' || $filetype=='jpeg') {\r
- \r
- $size = getimagesize($fullpath);\r
- \r
- $ratio = $size[1]/$size[0]; // ratio = height / width\r
- \r
- if ($ratio < 1) {\r
- $new_height = $this->getOption('thumbsize') * $size[1]/$size[0];\r
- $new_width = $this->getOption('thumbsize');\r
- }\r
- else {\r
- $new_height = $this->getOption('thumbsize');\r
- $new_width = $this->getOption('thumbsize') * $size[0]/$size[1];\r
- } \r
-\r
- $image_orig = imagecreatefromjpeg($fullpath);\r
- $image_new = imagecreatetruecolor($new_width, $new_height);\r
- \r
- imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]);\r
-\r
- $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype;\r
- \r
- imagejpeg ($image_new , $thumbfilename);\r
- \r
- // clear the memory\r
- imagedestroy($image_orig);\r
- imagedestroy($image_new);\r
- }\r
- \r
- // filetype is png\r
- if ($filetype=='png') {\r
- \r
- $size = getimagesize($fullpath);\r
- \r
- $ratio = $size[1]/$size[0]; // ratio = height / width\r
- \r
- if ($ratio < 1) {\r
- $new_height = $this->getOption('thumbsize') * $size[1]/$size[0];\r
- $new_width = $this->getOption('thumbsize');\r
- }\r
- else {\r
- $new_height = $this->getOption('thumbsize');\r
- $new_width = $this->getOption('thumbsize') * $size[0]/$size[1];\r
- } \r
-\r
- $image_orig = imagecreatefrompng($fullpath);\r
- $image_new = imagecreatetruecolor($new_width, $new_height);\r
- \r
- imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]);\r
-\r
- $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype;\r
- \r
- imagepng ($image_new , $thumbfilename);\r
- \r
- // clear the memory\r
- imagedestroy($image_orig);\r
- imagedestroy($image_new);\r
- }\r
- }\r
-}\r
-\r
-?>\r
+<?php
+
+class NP_ImageCreateThumbnail extends NucleusPlugin {
+
+/*
+ * Nucleus Plugin
+ *
+ * Copyright 2007 by Kai Greve
+ *
+ * This program is free software and open source software; you can redistribute
+ * it and/or modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA or visit
+ * http://www.gnu.org/licenses/gpl.html
+ *
+ *
+ * NP_ImageCreateThumbnail creates a thumbnail after an image is uploaded,
+ * it demonstrates the uages of the PostMediaUpload event
+ *
+ * History:
+ * v0.01: 2007-01-01
+ * - initial release
+ *
+ */
+
+ function getName() { return 'NP_ImageCreateThumbnail'; }
+ function getAuthor() { return 'Kai Greve'; }
+ function getURL() { return 'http://www.nucleuscms.org/'; }
+ function getVersion() { return '0.01'; }
+ function getDescription() { return 'Generates Thumbnails after an image is uploaded.'; }
+
+ function getMinNucleusVersion() { return 330; }
+
+ function supportsFeature($what) {
+ switch($what)
+ { case 'SqlTablePrefix':
+ return 1;
+ default:
+ return 0; }
+ }
+
+ function install() {
+ $this->createOption ('thumbsize', 'Maximal width (landscape format) or height (portrait format) for Thumbnails', 'text', '150');
+ }
+
+ function unInstall() {
+ }
+
+ function getEventList() {
+ return array('PostMediaUpload');
+ }
+
+
+ function event_PostMediaUpload(&$data) {
+
+ $collection = $data['collection'];
+ $mediadir = $data['mediadir'];
+ $filename = $data['filename'];
+ $fullpath = $mediadir.$filename;
+
+ // evaluate the filetype from the filename
+ $filetype = strtolower(substr($filename, strpos($filename, ".")+1));
+
+ // filetype is jpeg
+ if ($filetype=='jpg' || $filetype=='jpeg') {
+
+ $size = getimagesize($fullpath);
+
+ $ratio = $size[1]/$size[0]; // ratio = height / width
+
+ if ($ratio < 1) {
+ $new_height = $this->getOption('thumbsize') * $size[1]/$size[0];
+ $new_width = $this->getOption('thumbsize');
+ }
+ else {
+ $new_height = $this->getOption('thumbsize');
+ $new_width = $this->getOption('thumbsize') * $size[0]/$size[1];
+ }
+
+ $image_orig = imagecreatefromjpeg($fullpath);
+ $image_new = imagecreatetruecolor($new_width, $new_height);
+
+ imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]);
+
+ $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype;
+
+ imagejpeg ($image_new , $thumbfilename);
+
+ // clear the memory
+ imagedestroy($image_orig);
+ imagedestroy($image_new);
+ }
+
+ // filetype is png
+ if ($filetype=='png') {
+
+ $size = getimagesize($fullpath);
+
+ $ratio = $size[1]/$size[0]; // ratio = height / width
+
+ if ($ratio < 1) {
+ $new_height = $this->getOption('thumbsize') * $size[1]/$size[0];
+ $new_width = $this->getOption('thumbsize');
+ }
+ else {
+ $new_height = $this->getOption('thumbsize');
+ $new_width = $this->getOption('thumbsize') * $size[0]/$size[1];
+ }
+
+ $image_orig = imagecreatefrompng($fullpath);
+ $image_new = imagecreatetruecolor($new_width, $new_height);
+
+ imagecopyresampled($image_new, $image_orig, 0, 0, 0, 0, $new_width, $new_height, $size[0], $size[1]);
+
+ $thumbfilename = substr($fullpath, 0, strpos($fullpath, ".")).'_thumb.'.$filetype;
+
+ imagepng ($image_new , $thumbfilename);
+
+ // clear the memory
+ imagedestroy($image_orig);
+ imagedestroy($image_new);
+ }
+ }
+}
+
+?>