Interface ImageOperationService

All Known Implementing Classes:
DoNothingImageOperationService, ImageMagickImageOperationService

public interface ImageOperationService

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 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 the file and store the new file to the targetUrl
      Parameters:
      file - the image file to apply effects
      targetUrl - the target url to save file
      imageEffectsTags - 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 found
      StorageException - 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 the imageResource and store the new resource to the targetUrl
      Parameters:
      imageResource - the image resource to apply effects
      targetUrl - the target url to save file
      imageEffectsTags - 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 found
      StorageException - 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 the file 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 effects
      imageEffectsTags - 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 the imageResource 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 effects
      imageEffectsTags - 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 the imageEffectsTags is valid
      Parameters:
      imageEffectsTags - the image effects
      Returns:
      false if imageEffectsTags contains the effect names which is not configured by broadleaf.image.availableEffects property or NamedOperation and true otherwise
    • optimizeImage

      InputStream optimizeImage(org.springframework.web.multipart.MultipartFile toOptimize)
      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 by StandardOpenOption.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

      Map<String,File> 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.

      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

      void setNamedOperations(List<NamedOperation> namedOperations)
      Set the List of NamedOperation
      Parameters:
      namedOperations - the List of NamedOperation to set