ImageMagick Configuration
The mediaconversion extension enables you to convert bitmap image media with open source software.
The conversion attribute of a ConversionMediaFormat using the imagemagickConversionStrategy is interpreted as the command line arguments for the ImageMagick convert command
.
There are a few extensions to the conversion string given:
-
The {input} keyword is replaced by the absolute path of the conversion input file name. If the {input} marker is not found in the conversion string, the absolute path of the input file is prepended to the conversion command. For example, it is the first parameter passed to the ImageMagick convert command
. -
The {output} keyword is replaced by the absolute path of the output file just as the {input} marker. If no {output} marker is found in the conversion string, the absolute path of output file is appended to the conversion string, for example as the last command line parameter.
-
The {addOn#n} keyword is replaced the absolute path of the nth media in the list of additional medias associated to the ConversionMediaFormat. This feature makes it possible to include additional (static) input files in the conversion like adding a watermaker, applying color profiles, or putting an image onto a custom background.
For more information, refer to the ImageMagick documentation
and the ImageMagick extensive library of recipes
.
ImageMagick Configuration
|
Key |
Value Range |
Default |
Description |
|---|---|---|---|
|
imagemagick.bindir |
String |
embedded imagemagick binaries directory |
The binary directory of your local ImageMagick installation. |
|
imagemagick.configuration.directory |
String |
MAGICK_CONFIGURE_PATH |
Path to the ImageMagick configuration directory |
|
imagemagick.executable.convert |
String |
convert |
The executable name to be called to run the convert command (in the given imagemagick.bindir ). This is an advanced configuration option. |
|
imagemagick.executable.identify |
String |
identify |
The executable name to be called to run the identify command (in the given imagemagick.bindir ). This is an advanced configuration option. |
ImageMagick Environment Variables
All documented ImageMagick environment variables
are routed through when set in the JVM environment. With this you can configured a variety of ImageMagick options. The SAP Commerce system sets only two of these environment variables as follows:
-
MAGICK_TEMPORARY_PATH
The environment variable is sequenced accordingly:
-
If the environment variable is set in the JVM environment, it is used.
-
If the tmpDir property of the imagemagickConversionStrategy Spring bean is set, it is used.
-
If the property HYBRIS_TEMP_DIR system property is set, the ImageMagick temporary directory is set to $HYBRIS_TEMP_DIR /convert.
-
Otherwise the temporary directory is set to a /convert directory in the JVM default temporary directory ( $java.io.tmpdir/convert ).
-
-
MAGICK_CONFIGURE_PATH
To evaluate the correct ImageMagcik configuration folder to use, the following lookup sequence is applied:
-
If the configuration directory was set through Spring injection, it is used (the property value is disobeyed).
-
If the imagemagick.configuration.directory property is set, this path is used.
-
If the JVM MAGICK_CONFIGURE_PATH environment variable is set, it is used.
-
MimeMapping Configuration
ImageMagick relies on Mime Type detection on file extensions. This means to convert a media to a specific Mime Type, the file extension of the output file must be set accordingly. The imagemagickService uses the injected MimeMappingStrategy to resolve file extensions and Mime Types for a given file. TheDefaultMimeMappingStrategy is backed by the custom (file) extension properties set in the SAP Commerce project properties. This makes it easy to extend the Mime Type/file extension mapping even at runtime.
To introduce a new Mime Type/file extension pair, add the following properties to yourlocal.properties file:
media.customextension.${mimetype category}.${mimetypename}=${extension}
mediatype.by.fileextension.${file.extension}=${mimetype}
For example:
media.customextension.application.excel=xls mediatype.by.fileextension.xls=application/excel
Preventing Vulnerable Operations
Some operations that ImageMagick offers are vulnerable. To secure SAP Commerce, a comma-separated blocklist and a comma-separated allowlist are defined to prevent those vulnerable operations.
The blocklist definitions is:
imagemagick.executable.convert.commands.blacklist=write,clip-mask,mask,...
The allowlist definition is:
imagemagick.executable.convert.commands.whitelist=resize,crop,compose,...
You can't use both of those lists at the same time. To switch between them, use a switcher:
imagemagick.executable.convert.commands.validation.type=whitelist