]> source.dussan.org Git - nextcloud-server.git/commitdiff
improve imagick error handling
authorGeorg Ehrke <georg@ownCloud.com>
Thu, 30 May 2013 09:06:52 +0000 (11:06 +0200)
committerGeorg Ehrke <georg@ownCloud.com>
Thu, 30 May 2013 09:06:52 +0000 (11:06 +0200)
lib/preview/pdf.php
lib/preview/svg.php

index 85878a122a8dab6eb6def8cbe5f3bc0910f49d86..f1d0a33dc630cbef13c880dfa0a556a210841668 100644 (file)
@@ -19,8 +19,13 @@ if (extension_loaded('imagick')) {
                        $tmppath = $fileview->toTmpFile($path);
 
                        //create imagick object from pdf
-                       $pdf = new \imagick($tmppath . '[0]');
-                       $pdf->setImageFormat('jpg');
+                       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);
 
index 8bceeaf60d155a17ae87b321692fb4f62239fc01..76d81589bac475fb9762442a7fb539819dedb4ae 100644 (file)
@@ -16,17 +16,22 @@ if (extension_loaded('imagick')) {
                }
 
                public function getThumbnail($path,$maxX,$maxY,$scalingup,$fileview) {
-                       $svg = new \Imagick();
-                       $svg->setResolution($maxX, $maxY);
-
-                       $content = stream_get_contents($fileview->fopen($path, 'r'));
-                       if(substr($content, 0, 5) !== '<?xml') {
-                               $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
+                       try{
+                               $svg = new \Imagick();
+                               $svg->setResolution($maxX, $maxY);
+
+                               $content = stream_get_contents($fileview->fopen($path, 'r'));
+                               if(substr($content, 0, 5) !== '<?xml') {
+                                       $content = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . $content;
+                               }
+
+                               $svg->readImageBlob($content);
+                               $svg->setImageFormat('jpg');
+                       }catch(\Exception $e){
+                               \OC_Log::write('core', $e->getmessage(), \OC_Log::ERROR);
+                               return false;
                        }
 
-                       $svg->readImageBlob($content);
-                       $svg->setImageFormat('jpg');
-
                        //new image object
                        $image = new \OC_Image($svg);
                        //check if image object is valid