]> source.dussan.org Git - nextcloud-server.git/commitdiff
New generic class for Imagemagick conversions
authorOlivier Paroz <github@oparoz.com>
Sat, 4 Oct 2014 15:50:12 +0000 (17:50 +0200)
committerOlivier Paroz <github@oparoz.com>
Sat, 4 Oct 2014 15:50:12 +0000 (17:50 +0200)
config/config.sample.php
lib/private/mimetypes.list.php
lib/private/preview.php
lib/private/preview/bitmap.php [new file with mode: 0644]
lib/private/preview/pdf.php [deleted file]
lib/private/preview/tiff.php [deleted file]

index 88a52be03359c4e5987d165a348598dc79a6468e..48f0af9c99d8d7f7260389e6c5f0ec816a1b39ba 100755 (executable)
@@ -303,7 +303,10 @@ $CONFIG = array(
  *  - OC\Preview\SVG
  *  - OC\Preview\Movies
  *  - OC\Preview\PDF
- *  - OC\Preview\Tiff
+ *  - OC\Preview\TIFF
+ *  - OC\Preview\Illustrator
+ *  - OC\Preview\Postscript
+ *  - OC\Preview\Photoshop
  */
 'enabledPreviewProviders' => array(
        'OC\Preview\Image',
index a44ec1daa1eccf107f449d12ee670671d4287ec8..4f11829859ad2a29eed61c44b2f4b8971a5d52eb 100644 (file)
@@ -61,6 +61,7 @@ return array(
        'dv' => array('video/dv', null),
        'eot' => array('application/vnd.ms-fontobject', null),
        'epub' => array('application/epub+zip', null),
+       'eps' => array('application/postscript', null),
        'exe' => array('application/x-ms-dos-executable', null),
        'flac' => array('audio/flac', null),
        'flv' => array('video/x-flv', null),
@@ -120,6 +121,7 @@ return array(
        'ppt' => array('application/vnd.ms-powerpoint', null),
        'pptm' => array('application/vnd.ms-powerpoint.presentation.macroEnabled.12', null),
        'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', null),
+       'ps' => array('application/postscript', null),
        'psd' => array('application/x-photoshop', null),
        'py' => array('text/x-python', null),
        'rar' => array('application/x-rar-compressed', null),
index c93f5d5516fdd269ce458086888ed488a23cd989..4b21e324037e2d9a2e26c4a4bb9b196a5525d3d6 100755 (executable)
@@ -19,11 +19,10 @@ use OCP\Files\NotFoundException;
 require_once 'preview/image.php';
 require_once 'preview/movies.php';
 require_once 'preview/mp3.php';
-require_once 'preview/pdf.php';
 require_once 'preview/svg.php';
 require_once 'preview/txt.php';
 require_once 'preview/office.php';
-require_once 'preview/tiff.php';
+require_once 'preview/bitmap.php';
 
 class Preview {
        //the thumbnail folder
@@ -691,7 +690,10 @@ class Preview {
                 *  - OC\Preview\SVG
                 *  - OC\Preview\Movies
                 *  - OC\Preview\PDF
-                *  - OC\Preview\Tiff
+                *  - OC\Preview\TIFF
+                *  - OC\Preview\Illustrator
+                *  - OC\Preview\Postscript
+                *  - OC\Preview\Photoshop
                 */
                if(empty(self::$enabledProviders)) {
                        self::$enabledProviders = \OC::$server->getConfig()->getSystemValue('enabledPreviewProviders', array(
diff --git a/lib/private/preview/bitmap.php b/lib/private/preview/bitmap.php
new file mode 100644 (file)
index 0000000..748a63a
--- /dev/null
@@ -0,0 +1,117 @@
+<?php
+/**
+ * Copyright (c) 2013-2014 Georg Ehrke georg@ownCloud.com
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+namespace OC\Preview;
+
+use Imagick;
+
+if (extension_loaded('imagick')) {
+
+       $checkImagick = new Imagick();
+
+       class Bitmap extends Provider {
+
+               public function getMimeType() {
+                       return null;
+               }
+
+               public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
+                       $tmpPath = $fileview->toTmpFile($path);
+
+                       //create imagick object from bitmap or vector file
+                       try{
+                               // Layer 0 contains either the bitmap or
+                               // a flat representation of all vector layers
+                               $bp = new Imagick($tmpPath . '[0]');
+                               
+                               $bp->setImageFormat('png');
+                       } catch (\Exception $e) {
+                               \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+                               return false;
+                       }
+
+                       unlink($tmpPath);
+                       
+                       //new bitmap image object
+                       $image = new \OC_Image($bp);
+                       //check if image object is valid
+                       return $image->valid() ? $image : false;
+               }
+
+       }
+       
+       if(count($checkImagick->queryFormats('PDF')) === 1) {
+       
+               //.pdf
+               class PDF extends Bitmap {
+
+                       public function getMimeType() {
+                               return '/application\/pdf/';
+                       }
+
+               }
+               
+               \OC\Preview::registerProvider('OC\Preview\PDF');
+       }
+       
+       if(count($checkImagick->queryFormats('TIFF')) === 1) {
+       
+               //.tiff
+               class TIFF extends Bitmap {
+
+                       public function getMimeType() {
+                               return '/image\/tiff/';
+                       }
+
+               }
+               
+               \OC\Preview::registerProvider('OC\Preview\TIFF');
+       }
+
+       if(count($checkImagick->queryFormats('AI')) === 1) {
+       
+               //.ai
+               class Illustrator extends Bitmap {
+
+                       public function getMimeType() {
+                               return '/application\/illustrator/';
+                       }
+
+               }
+               
+               \OC\Preview::registerProvider('OC\Preview\Illustrator');
+       }
+       
+       // Requires adding 'eps' => array('application/postscript', null), to lib/private/mimetypes.list.php
+       if(count($checkImagick->queryFormats('EPS')) === 1) {
+
+               //.eps
+               class Postscript extends Bitmap {
+
+                       public function getMimeType() {
+                               return '/application\/postscript/';
+                       }
+
+               }
+
+               \OC\Preview::registerProvider('OC\Preview\Postscript');
+       }
+       
+       if(count($checkImagick->queryFormats('PSD')) === 1) {
+       
+               //.psd
+               class Photoshop extends Bitmap {
+
+                       public function getMimeType() {
+                               return '/application\/x-photoshop/';
+                       }
+
+               }
+               
+               \OC\Preview::registerProvider('OC\Preview\Photoshop');
+       }
+}
diff --git a/lib/private/preview/pdf.php b/lib/private/preview/pdf.php
deleted file mode 100644 (file)
index 4b88b1a..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-namespace OC\Preview;
-
-use Imagick;
-
-if (extension_loaded('imagick')) {
-
-       $checkImagick = new Imagick();
-
-       if(count($checkImagick->queryFormats('PDF')) === 1) {
-
-               class PDF extends Provider {
-
-                       public function getMimeType() {
-                               return '/application\/pdf/';
-                       }
-
-                       public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-                               $tmpPath = $fileview->toTmpFile($path);
-
-                               //create imagick object from pdf
-                               try{
-                                       $pdf = new Imagick($tmpPath . '[0]');
-                                       $pdf->setImageFormat('jpg');
-                               } catch (\Exception $e) {
-                                       \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
-                                       return false;
-                               }
-
-                               unlink($tmpPath);
-
-                               //new image object
-                               $image = new \OC_Image($pdf);
-                               //check if image object is valid
-                               return $image->valid() ? $image : false;
-                       }
-
-               }
-
-               \OC\Preview::registerProvider('OC\Preview\PDF');
-       }
-}
diff --git a/lib/private/preview/tiff.php b/lib/private/preview/tiff.php
deleted file mode 100644 (file)
index c435ec7..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * Copyright (c) 2013-2014 Georg Ehrke georg@ownCloud.com
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-namespace OC\Preview;
-
-use Imagick;
-
-if (extension_loaded('imagick')) {
-
-        $checkImagick = new Imagick();
-
-        if(count($checkImagick->queryFormats('TIFF')) === 1) {
-
-                class TIFF extends Provider {
-
-                        public function getMimeType() {
-                                return '/image\/tiff/';
-                        }
-
-                        public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
-                                $tmpPath = $fileview->toTmpFile($path);
-
-                                //create imagick object from TIFF
-                                try{
-                                        $tiff = new Imagick($tmpPath);
-                                        $tiff->setImageFormat('png');
-                                } catch (\Exception $e) {
-                                        \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
-                                        return false;
-                                }
-
-                                unlink($tmpPath);
-
-                                //new image object
-                                $image = new \OC_Image($tiff);
-                                //check if image object is valid
-                                return $image->valid() ? $image : false;
-                        }
-
-                }
-
-                \OC\Preview::registerProvider('OC\Preview\TIFF');
-        }
-}