Class ImageMagickMediaConversionStrategy
- All Implemented Interfaces:
MediaConversionStrategy
MediaConversionStrategy backed by ImageMagick to do
various image conversions.
This MediaConversionStrategy takes the conversion string (ConversionMediaFormatModel.getConversion())
and turns it to a image magick convert command line. The convert executable and input file (the original media's
data) will be prepended to the command. The output file (which is a temporary file), will be appended to the command
array. Input file and output file will not be included in the command array if you specify a
{input} or {output} token in your conversion string. In the latter case these tokens will
be replaced with the absolute file names of the input or output respectively.
Additionally if there are ConversionMediaFormatModel.getMediaAddOns() present, occurrences of the
"{addOn#X}"
(where X denotes the position within the media add on list (starting with 1!)) will e replaced by the
absolute path names of these medias.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringToken to be replaced with add on file names within the conversion command (if present).static final StringToken to be replaced with the conversions input file name within the conversion command (if present).static final StringToken to be replaced with the conversions output file name within the conversion command (if present).Fields inherited from class de.hybris.platform.mediaconversion.imagemagick.BasicImageMagickStrategy
EMBEDDED_CONFIG_DIR, IMAGEMAGICK_CONFIGURATION_DIRECTORY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuildCommand(MediaConversionService mediaConversionService, File input, File output, ConversionMediaFormatModel format) Build the imagemagick command to execute from the given input.buildCommand(MediaConversionService mediaConversionService, String input, String output, ConversionMediaFormatModel format) Build the imagemagick command to execute from the given input.convert(MediaConversionService mediaConversionService, MediaModel input, ConversionMediaFormatModel format) Converts the givenparentmedia to the givenformat.protected voidconvert(MediaConversionService mediaConversionService, File input, File target, ConversionMediaFormatModel format) Does the actual conversion based.protected StringreplaceAddOns(MediaConversionService mediaConversionService, String commandPart, ConversionMediaFormatModel format) Replaces all "{addOn#X}" occurrences in the givencommandPartand return it's new value, if there are mediaAddOns set on the givenConversionMediaFormatModel.retrieveFile(MediaModel media) Locates a localFilefor the givenMediaModelor throws aIOExceptionif no such file is accessible.voidvoidsetImageMagickService(ImageMagickService magickService) voidsetMediaService(MediaService mediaService) voidsetMimeMappingStrategy(MimeMappingStrategy mimeMappingStrategy) protected StringtargetFileExtension(ConversionMediaFormatModel format, MediaModel input) Returns the file extension for the targeted format.Methods inherited from class de.hybris.platform.mediaconversion.imagemagick.BasicImageMagickStrategy
getConfigurationDirectory, getConfigurationService, getTmpDir, setConfigurationDirectory, setConfigurationService, setTmpDir
-
Field Details
-
CONVERSION_INPUT_TOKEN
Token to be replaced with the conversions input file name within the conversion command (if present).- See Also:
-
CONVERSION_OUTPUT_TOKEN
Token to be replaced with the conversions output file name within the conversion command (if present).- See Also:
-
CONVERSION_ADDON_TOKEN
Token to be replaced with add on file names within the conversion command (if present). Note that the 'X' will be replaced by the addOn's media index in the list of addOn medias.- See Also:
-
-
Constructor Details
-
ImageMagickMediaConversionStrategy
public ImageMagickMediaConversionStrategy()
-
-
Method Details
-
convert
public MediaModel convert(MediaConversionService mediaConversionService, MediaModel input, ConversionMediaFormatModel format) throws MediaConversionException Converts the givenparentmedia to the givenformat.- Specified by:
convertin interfaceMediaConversionStrategy- Parameters:
mediaConversionService- to avoid cyclic IoC errors, theMediaConversionServiceis passed.input- the media to convertformat- the format to convert to- Returns:
- a fresh created media in the given format
- Throws:
MediaConversionException- if the conversion could not be processed due to a technical reason- See Also:
-
convert
protected void convert(MediaConversionService mediaConversionService, File input, File target, ConversionMediaFormatModel format) throws IOException Does the actual conversion based.- Parameters:
mediaConversionService- to avoid cyclic IoC errors, theMediaConversionServiceis passed.input- the local input filetarget- the output fileformat- the conversion format specification- Throws:
IOException- on any conversion error
-
targetFileExtension
protected String targetFileExtension(ConversionMediaFormatModel format, MediaModel input) throws IOException, MediaConversionException Returns the file extension for the targeted format. If no mime type is set on the givenConversionMediaFormatModelthe file extension of the input mime type is used. If this does not lead to success, the file extension of the input medias URL is extracted. As a last fallback, the default file extension is returned.- Parameters:
format- the targeted formatinput- original media- Returns:
- the targeted file extensions never
null. - Throws:
IOException- if a technical error occursMediaConversionException- if no file extension could be found for the mime type specified on the target format or (if no explicit mime type is given) if the file extension could not be extracted from the input's URL.
-
buildCommand
protected List<String> buildCommand(MediaConversionService mediaConversionService, File input, File output, ConversionMediaFormatModel format) throws IOException Build the imagemagick command to execute from the given input.- Parameters:
mediaConversionService- to avoid cyclic IoC errors, theMediaConversionServiceis passed.input- the input fileoutput- the output fileformat- the conversion specification.- Returns:
- the command to execute (excluding the 'convert' executable).
- Throws:
IOException- if a technical error occurs- See Also:
-
buildCommand
protected List<String> buildCommand(MediaConversionService mediaConversionService, String input, String output, ConversionMediaFormatModel format) throws IOException Build the imagemagick command to execute from the given input.- Parameters:
mediaConversionService- to avoid cyclic IoC errors, theMediaConversionServiceis passed.input- the absolute path to input fileoutput- the absolute path to output fileformat- the conversion specification.- Returns:
- the command to execute (excluding the 'convert' executable).
- Throws:
IOException- if a technical error occurs- See Also:
-
replaceAddOns
protected String replaceAddOns(MediaConversionService mediaConversionService, String commandPart, ConversionMediaFormatModel format) throws IOException Replaces all "{addOn#X}" occurrences in the givencommandPartand return it's new value, if there are mediaAddOns set on the givenConversionMediaFormatModel.- Parameters:
mediaConversionService- reference to theMediaConversionServiceto use forFileretrievalcommandPart- the command part to manipulateformat- theConversionMediaFormatModelspecifying the mediaAddOns- Returns:
- the manipulated command part
- Throws:
IOException- if a mediaAddOn cannot be accessed
-
retrieveFile
Locates a localFilefor the givenMediaModelor throws aIOExceptionif no such file is accessible.- Parameters:
media- theMediaModelin question.- Returns:
- a local (readable) File representation for the given
MediaModel. - Throws:
IOException- if no such file is accessible.
-
getMimeMappingStrategy
-
setMimeMappingStrategy
-
getConvertedMediaCreationStrategy
-
setConvertedMediaCreationStrategy
-
getImageMagickService
-
setImageMagickService
-
getMediaService
-
setMediaService
-