Optional override for the ImageMagick filter
authorAlexander Ebert <ebert@woltlab.com>
Mon, 2 Sep 2019 14:44:12 +0000 (16:44 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 2 Sep 2019 14:44:12 +0000 (16:44 +0200)
Closes #3057

wcfsetup/install/files/lib/system/image/adapter/ImagickImageAdapter.class.php

index 36bb7bcd097aef09c2e15e8e6ffc0227e6e2d90b..ca392af0b2c005354cbaf47a4147ff5748ae9448 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\image\adapter;
+use wcf\system\event\EventHandler;
 use wcf\system\exception\SystemException;
 
 /**
@@ -179,7 +180,7 @@ class ImagickImageAdapter implements IImageAdapter {
                else {
                        $this->clip($originX, $originY, $originWidth, $originHeight);
                        
-                       $this->imagick->resizeImage($targetWidth, $targetHeight, \Imagick::FILTER_POINT, 0);
+                       $this->imagick->resizeImage($targetWidth, $targetHeight, $this->getResizeFilter(), 0);
                }
        }
        
@@ -416,6 +417,24 @@ class ImagickImageAdapter implements IImageAdapter {
                // does nothing
        }
        
+       /**
+        * Returns the preferred image filter used during image resizing.
+        * 
+        * @return int
+        */
+       protected function getResizeFilter() {
+               static $filter;
+               
+               if ($filter === null) {
+                       $parameters = ['filter' => null];
+                       EventHandler::getInstance()->fireAction($this, 'getResizeFilter', $parameters);
+                       
+                       $filter = $parameters['filter'] ?? \Imagick::FILTER_POINT;
+               }
+               
+               return $filter;
+       }
+       
        /**
         * @inheritDoc
         */