diff --git a/Plugin.php b/Plugin.php index 13e6567..aca953d 100644 --- a/Plugin.php +++ b/Plugin.php @@ -44,15 +44,14 @@ public function register() * @return array */ public function boot() - { + { Image::configure(array( 'driver' => 'imagick' )); - + Event::listen('system.resizer.processResize', function ($resizer, $tempPath) { - EventLog::add("TEMP PATH: $tempPath"); // Get the configuration options the user has sumitted $config = $resizer->getConfig(); $options = array_get($config, 'options', []); @@ -83,9 +82,9 @@ public function boot() if (!$filters) { // End here if there are no filters to apply \Winter\Storm\Database\Attach\Resizer::open($tempPath)->resize($width, $height, $options)->save($newPath); - if ($newPath != $tempPath) - File::move($newPath, $tempPath); - + if ($newPath != $tempPath) + File::move($newPath, $tempPath); + // Prevent any other resizing replacer logic from running return true; } @@ -104,13 +103,13 @@ public function boot() if (!$filters) { // End here if there are no filters to apply $image = Image::make($tempPath)->resize($width, $height)->save($newPath, $quality, $extension); - if ($newPath != $tempPath) + if ($newPath != $tempPath) File::move($newPath, $tempPath); - + // Prevent any other resizing replacer logic from running return true; } - else + else { // Resize $image = Image::make($tempPath)->resize($width, $height); @@ -167,11 +166,11 @@ public function boot() break; /* Not working - review needed - + case 'invert': $image=$image->invert(); break; - + */ case 'limitColors': @@ -211,17 +210,17 @@ public function boot() elseif (strcmp($filters, "")) $image = eval("{ return \$image->" . $filters . "; }"); $image->save($newPath, $quality, $extension); - if ($newPath != $tempPath) + if ($newPath != $tempPath) File::move($newPath, $tempPath); // Prevent any other resizing replacer logic from running return true; }); - - } - - + + } + + /** * Registers any front-end components implemented in this plugin. @@ -231,7 +230,7 @@ public function boot() public function registerComponents() { return []; // Remove this line to activate - + } /** @@ -242,7 +241,7 @@ public function registerComponents() public function registerPermissions() { return []; // Remove this line to activate - + } /** @@ -253,13 +252,14 @@ public function registerPermissions() public function registerNavigation() { return []; // Remove this line to activate - + } public function registerMarkupTags() { - return ['filters' => ['iresize' => [MediaExtensions::class , 'iresize'], 'ifilter' => [MediaExtensions::class , 'iresize'] - - ], 'functions' => ['exif' => [MediaExtensions::class , 'exif'], 'iptc' => [MediaExtensions::class , 'iptc'], ], ]; + return [ + 'filters' => ['iresize' => [MediaExtensions::class , 'iresize'], 'ifilter' => [MediaExtensions::class , 'iresize'], ], + 'functions' => ['exif' => [MediaExtensions::class , 'exif'], 'iptc' => [MediaExtensions::class , 'iptc'], ] + ]; } } diff --git a/classes/MediaExtensions.php b/classes/MediaExtensions.php index 2d78a7a..2f2b745 100644 --- a/classes/MediaExtensions.php +++ b/classes/MediaExtensions.php @@ -18,15 +18,15 @@ class MediaExtensions extends \Backend\Classes\Controller 'imageTypes' => [ 'image/webp' => [ 'extension' => 'webp', - 'quality' => 50, + 'quality' => 60, ], 'image/jpg' => [ 'extension' => 'jpg', - 'quality' => 60, + 'quality' => 70, ], 'image/jpeg' => [ 'extension' => 'jpeg', - 'quality' => 60, + 'quality' => 70, ], 'image/gif' => [ 'extension' => 'gif', @@ -50,63 +50,63 @@ public static function acceptsFormat($type) return in_array($type, $acceptableTypes) || in_array("image/$type", $acceptableTypes); } - - - public static function iresize($image, $width=null, $height=null, $filters=null, $extension=null, $quality=null) + + + public static function iresize($image, $width=null, $height=null, $filters=null, $extension=null, $quality=null) { // Check if the file exists $path = public_path(parse_url($image, PHP_URL_PATH)); if (!File::exists($path)) { return $image; } - + // Uxtension must be all lower case if ($extension) $extension = strtolower($extension); - + // Use the explicitly spcifie format or provide the best available if no format has been specified foreach (static::$defaultOptions['imageTypes'] as $type => $typeOptions) { - + $ext = array_get($typeOptions, 'extension'); - + if (($extension && !strcmp($ext, $extension)) || (!$extension && static::acceptsFormat($type))) { - + if (!$quality) $quality = array_get($typeOptions, 'quality', 90); $publicPath = File::localToPublic($path); $resizerPath = ImageResizer::filterGetUrl($publicPath, $width, $height, ['extension' => $ext, 'quality'=> $quality, 'filters' => $filters ]); - + $url = urldecode(urldecode($resizerPath)); $resizedImagePath = base_path(substr($url, strpos($url, "//"))); - + /* - + if (is_file($resizedImagePath) && ( filectime($resizedImagePath) < filectime(base_path() . $image))) { // The image is newer than the resiuzed one, unlink the resized, so it gets re-generated. // EventLog::add("isresize - Resized image removed as there is a new original in " . __FILE__); unlink($resizedImagePath); } - + */ - + return $resizerPath; - + } } - + EventLog::add("Could not resize image, unknown format $extension in " . __FILE__); return $image; } - - public static function exif($image, $type=null) + + public static function exif($image, $type=null) { if (!$type) return $data = Image::make(base_path(). $image)->exif(); else return Image::make($image)->exif($type); } - - public static function iptc($image, $type=null) + + public static function iptc($image, $type=null) { if (!$type) return $data = Image::make(base_path().$image)->iptc();