]> git.mxchange.org Git - friendica.git/blobdiff - src/Object/Image.php
Merge pull request #12390 from annando/fixes
[friendica.git] / src / Object / Image.php
index a79f3a5688bedff988a5fee5db39d164ee16e5dc..06498f963fcb859b78d4d96c5381824ddd6b0794 100644 (file)
@@ -733,25 +733,34 @@ class Image
         */
        public function getBlurHash(): string
        {
-               $width = $this->getWidth();
-               $height = $this->getHeight();
+               $image = New Image($this->asString());
+               if (empty($image)) {
+                       return '';
+               }
+
+               $width = $image->getWidth();
+               $height = $image->getHeight();
 
                if (max($width, $height) > 90) {
-                       $this->scaleDown(90);
-                       $width = $this->getWidth();
-                       $height = $this->getHeight();
+                       $image->scaleDown(90);
+                       $width = $image->getWidth();
+                       $height = $image->getHeight();
                }
 
                $pixels = [];
                for ($y = 0; $y < $height; ++$y) {
                        $row = [];
                        for ($x = 0; $x < $width; ++$x) {
-                               if ($this->isImagick()) {
-                                       $colors = $this->image->getImagePixelColor($x, $y)->getColor();
+                               if ($image->isImagick()) {
+                                       try {
+                                               $colors = $image->image->getImagePixelColor($x, $y)->getColor();
+                                       } catch (\Throwable $th) {
+                                               return '';
+                                       }
                                        $row[] = [$colors['r'], $colors['g'], $colors['b']];
                                } else {
-                                       $index = imagecolorat($this->image, $x, $y);
-                                       $colors = @imagecolorsforindex($this->image, $index);
+                                       $index = imagecolorat($image->image, $x, $y);
+                                       $colors = @imagecolorsforindex($image->image, $index);
                                        $row[] = [$colors['red'], $colors['green'], $colors['blue']];
                                }
                        }
@@ -798,11 +807,11 @@ class Image
                        }
                }
 
-               if (!$this->isImagick()) {
+               if ($this->isImagick()) {
+                       $this->image->drawImage($draw);
+               } else {
                        $this->width  = imagesx($this->image);
                        $this->height = imagesy($this->image);
-               } else {
-                       $this->image->drawImage($draw);
                }
 
                $this->valid = true;