]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Image.php
Merge pull request #10086 from nupplaphil/feat/install_testrewrite
[friendica.git] / src / Object / Image.php
index b69682ca6140bf301572ebf1cade688a4a49b66c..4645a8678a59fd1e330614315a364dfb01005a07 100644 (file)
@@ -22,7 +22,6 @@
 namespace Friendica\Object;
 
 use Exception;
-use Friendica\Core\System;
 use Friendica\DI;
 use Friendica\Util\Images;
 use Imagick;
@@ -123,7 +122,11 @@ class Image
                        $this->image->setFormat($format);
 
                        // Always coalesce, if it is not a multi-frame image it won't hurt anyway
-                       $this->image = $this->image->coalesceImages();
+                       try {
+                               $this->image = $this->image->coalesceImages();
+                       } catch (Exception $e) {
+                               return false;
+                       }
 
                        /*
                         * setup the compression here, so we'll do it only once
@@ -538,7 +541,12 @@ class Image
                        do {
                                // FIXME - implement horizontal bias for scaling as in following GD functions
                                // to allow very tall images to be constrained only horizontally.
-                               $this->image->scaleImage($dest_width, $dest_height);
+                               try {
+                                       $this->image->scaleImage($dest_width, $dest_height);
+                               } catch (Exception $e) {
+                                       // Imagick couldn't use the data
+                                       return false;
+                               }
                        } while ($this->image->nextImage());
 
                        // These may not be necessary anymore
@@ -567,6 +575,21 @@ class Image
                return true;
        }
 
+       /**
+        * Convert a GIF to a PNG to make it static
+        */
+       public function toStatic()
+       {
+               if ($this->type != 'image/gif') {
+                       return;
+               }
+
+               if ($this->isImagick()) {
+                       $this->type == 'image/png';
+                       $this->image->setFormat('png');
+               }
+       }
+
        /**
         * @param integer $max maximum
         * @param integer $x   x coordinate