Add Imagick adapter support

Signed-off-by: Andy Miller <rhuk@mac.com>
This commit is contained in:
Andy Miller
2025-08-16 12:52:55 +01:00
parent 8811b7aad0
commit 7236862a15
4 changed files with 35 additions and 1 deletions

View File

@@ -46,7 +46,7 @@
"filp/whoops": "~2.9",
"matthiasmullie/minify": "^1.3",
"monolog/monolog": "~1.25",
"getgrav/image": "^3.0",
"getgrav/image": "^4.0",
"getgrav/cache": "^2.0",
"donatj/phpuseragentparser": "~1.1",
"pimple/pimple": "~3.5.0",

View File

@@ -1238,6 +1238,16 @@ form:
title: PLUGIN_ADMIN.MEDIA
underline: true
images.adapter:
type: select
size: small
label: PLUGIN_ADMIN.IMAGES_ADAPTER
help: PLUGIN_ADMIN.IMAGES_ADAPTER_HELP
highlight: gd
options:
imagick: Imagick
gd: GD (PHP built-in)
images.default_image_quality:
type: range
append: '%'

View File

@@ -156,6 +156,7 @@ debugger:
close_connection: true # Close the connection before calling onShutdown(). false for debugging
images:
adapter: gd # Image adapter to use: gd | imagick
default_image_quality: 85 # Default image quality to use when resampling images (85%)
cache_all: false # Cache all image by default
cache_perms: '0755' # MUST BE IN QUOTES!! Default cache folder perms. Usually '0755' or '0775'

View File

@@ -31,6 +31,29 @@ use function in_array;
*/
class ImageFile extends Image
{
/**
* Image constructor with adapter configuration from Grav.
*
* @param string|null $originalFile
* @param int|null $width
* @param int|null $height
*/
public function __construct($originalFile = null, $width = null, $height = null)
{
parent::__construct($originalFile, $width, $height);
// Set the adapter based on Grav configuration
$grav = Grav::instance();
$adapter = $grav['config']->get('system.images.adapter', 'gd');
try {
$this->setAdapter($adapter);
} catch (Exception $e) {
$grav['log']->error(
'Image adapter "' . $adapter . '" is not available. Falling back to GD adapter.'
);
}
}
/**
* Destruct also image object.
*/