Interface ImageOperationService
- All Known Implementing Classes:
DoNothingImageOperationService
,ImageMagickImageOperationService
This interface exposes methods required to apply such image effects like resize, crop, sharpen.
To control the supported operation use property broadleaf.image.availableEffects For example to add the ImageMagick operation colorize add it to this property
- Author:
- Dima Myroniuk (dmyroniuk)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionapplyEffects
(ResourceWithMetadata imageResource, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to theimageResource
and save it to the temp file.applyEffects
(File file, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to thefile
and save it to the temp file.applyEffectsAndStoreModifiedFile
(File file, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Deprecated, for removal: This API element is subject to removal in a future version.applyEffectsAndStoreModifiedResource
(ResourceWithMetadata imageResource, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to theimageResource
and store the new resource to thetargetUrl
boolean
isValidImageEffectTags
(org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Check that theimageEffectsTags
is validoptimizeImage
(org.springframework.web.multipart.MultipartFile toOptimize) Optimizes a GIF, PNG, or JPEG in an attempt to reduce its size.optimizeImageBatch
(Map<String, File> imagesToOptimize) This method will batch-optimize any GIF, PNG, and JPEG image files in the input map in an attempt to reduce their sizes.void
setNamedOperations
(List<NamedOperation> namedOperations) Set theList
ofNamedOperation
-
Method Details
-
applyEffectsAndStoreModifiedFile
@Deprecated(since="2.0.1", forRemoval=true) File applyEffectsAndStoreModifiedFile(File file, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Deprecated, for removal: This API element is subject to removal in a future version.Apply the effects to thefile
and store the new file to thetargetUrl
- Parameters:
file
- the image file to apply effectstargetUrl
- the target url to save fileimageEffectsTags
- the image effects- Returns:
- the new saved file
- Throws:
ImageOperationException
- - Thrown when an exception occurs applying the effects. This could occur when creating the new file, the thread performing the operation is interrupted, or some other reason.ResourceResolutionException
- if the new file can't be foundStorageException
- if an error occurred while trying to save the image to the file system.
-
applyEffectsAndStoreModifiedResource
ResourceWithMetadata applyEffectsAndStoreModifiedResource(ResourceWithMetadata imageResource, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to theimageResource
and store the new resource to thetargetUrl
- Parameters:
imageResource
- the image resource to apply effectstargetUrl
- the target url to save fileimageEffectsTags
- the image effects- Returns:
- the new saved resource
- Throws:
ImageOperationException
- - Thrown when an exception occurs applying the effects. This could occur when creating the new file, the thread performing the operation is interrupted, or some other reason.ResourceResolutionException
- if the new file can't be foundStorageException
- if an error occurred while trying to save the image to the file system.
-
applyEffects
InputStream applyEffects(File file, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to thefile
and save it to the temp file. Note: The temp file will be deleted on close.StandardOpenOption.DELETE_ON_CLOSE
- Parameters:
file
- the image file to apply effectsimageEffectsTags
- the image effects- Returns:
- the
InputStream
to the new temp file. - Throws:
ImageOperationException
- - Thrown when an exception occurs applying the effects. This could occur when creating the new file, the thread performing the operation is interrupted, or some other reason.
-
applyEffects
InputStream applyEffects(ResourceWithMetadata imageResource, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Apply the effects to theimageResource
and save it to the temp file. Note: The temp file will be deleted on close.StandardOpenOption.DELETE_ON_CLOSE
- Parameters:
imageResource
- the image resource to apply effectsimageEffectsTags
- the image effects- Returns:
- the
InputStream
to the new temp file. - Throws:
ImageOperationException
- - Thrown when an exception occurs applying the effects. This could occur when creating the new file, the thread performing the operation is interrupted, or some other reason.
-
isValidImageEffectTags
boolean isValidImageEffectTags(org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Check that theimageEffectsTags
is valid- Parameters:
imageEffectsTags
- the image effects- Returns:
- false if
imageEffectsTags
contains the effect names which is not configured by broadleaf.image.availableEffects property orNamedOperation
and true otherwise
-
optimizeImage
Optimizes a GIF, PNG, or JPEG in an attempt to reduce its size.If
toOptimize
is a GIF, PNG, or JPEG, it will be copied to a temporary file, optimized, and its stream will be returned. When this stream is closed, the temporary file will be deleted, as documented byStandardOpenOption.DELETE_ON_CLOSE
.The given file itself is not modified, as the optimization is applied to a copy.
If
toOptimize
was not a GIF, PNG, or JPEG, the returned value will just be its unmodified stream. The temp file will be deleted on close.StandardOpenOption.DELETE_ON_CLOSE
- Parameters:
toOptimize
- the file to be optimized- Returns:
- the
InputStream
of the optimized file, or of the unmodified file if not a GIF, PNG, or JPEG - Throws:
ImageOptimizationException
- Throw when the optimization fails. This could be because a stream to read the image could not be opened, the thread performing the optimization was interrupted, or some other reason.
-
optimizeImageBatch
This method will batch-optimize any GIF, PNG, and JPEG image files in the input map in an attempt to reduce their sizes.This operation will write over the given files themselves.
- Parameters:
imagesToOptimize
- a map of normalized URLs to files that should be optimized. The content type of the files will be determined purely by examining the URLs (key), and this will be used to determine whether the file is eligible for optimization.- Returns:
- a map of the given URLs to the corresponding optimized files. Only files that were successfully optimized will be present in this result. While the resulting map will be a new instance, the instances of any keys/values will be the same as those that were supplied.
- Throws:
ImageOptimizationException
- if the optimization fails. This could be because the thread performing the optimization was interrupted, or an I/O issue, or some other reason.
-
setNamedOperations
Set theList
ofNamedOperation
- Parameters:
namedOperations
- theList
ofNamedOperation
to set
-
applyEffectsAndStoreModifiedResource(ResourceWithMetadata, String, MultiValueMap)