Class DoNothingImageOperationService
- All Implemented Interfaces:
ImageOperationService
ImageOperationService
implementation that does nothing.
Since some clients may not want to perform image operations, the presence of this service avoids
introducing a hard requirement on the default implementation,
ImageMagickImageOperationService
, which introduces a requirement on the ImageMagick
commandline utility.
- Author:
- Samarth Dhruva (samarthd)
-
Constructor Summary
Constructors -
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) Apply the effects to thefile
and store the new file to thetargetUrl
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
-
Constructor Details
-
DoNothingImageOperationService
public DoNothingImageOperationService()
-
-
Method Details
-
applyEffectsAndStoreModifiedFile
public File applyEffectsAndStoreModifiedFile(File file, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Description copied from interface:ImageOperationService
Apply the effects to thefile
and store the new file to thetargetUrl
- Specified by:
applyEffectsAndStoreModifiedFile
in interfaceImageOperationService
- Parameters:
file
- the image file to apply effectstargetUrl
- the target url to save fileimageEffectsTags
- the image effects- Returns:
- the new saved file
-
applyEffectsAndStoreModifiedResource
public ResourceWithMetadata applyEffectsAndStoreModifiedResource(ResourceWithMetadata imageResource, String targetUrl, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Description copied from interface:ImageOperationService
Apply the effects to theimageResource
and store the new resource to thetargetUrl
- Specified by:
applyEffectsAndStoreModifiedResource
in interfaceImageOperationService
- Parameters:
imageResource
- the image resource to apply effectstargetUrl
- the target url to save fileimageEffectsTags
- the image effects- Returns:
- the new saved resource
-
applyEffects
public InputStream applyEffects(File file, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Description copied from interface:ImageOperationService
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
- Specified by:
applyEffects
in interfaceImageOperationService
- Parameters:
file
- the image file to apply effectsimageEffectsTags
- the image effects- Returns:
- the
InputStream
to the new temp file.
-
applyEffects
public InputStream applyEffects(ResourceWithMetadata imageResource, org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Description copied from interface:ImageOperationService
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
- Specified by:
applyEffects
in interfaceImageOperationService
- Parameters:
imageResource
- the image resource to apply effectsimageEffectsTags
- the image effects- Returns:
- the
InputStream
to the new temp file.
-
isValidImageEffectTags
public boolean isValidImageEffectTags(org.springframework.util.MultiValueMap<String, String> imageEffectsTags) Description copied from interface:ImageOperationService
Check that theimageEffectsTags
is valid- Specified by:
isValidImageEffectTags
in interfaceImageOperationService
- 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
Description copied from interface:ImageOperationService
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
- Specified by:
optimizeImage
in interfaceImageOperationService
- 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
-
optimizeImageBatch
Description copied from interface:ImageOperationService
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.
- Specified by:
optimizeImageBatch
in interfaceImageOperationService
- 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.
-
setNamedOperations
Description copied from interface:ImageOperationService
Set theList
ofNamedOperation
- Specified by:
setNamedOperations
in interfaceImageOperationService
- Parameters:
namedOperations
- theList
ofNamedOperation
to set
-