Class ImageCrop

All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasStyle, Serializable

@NpmPackage(value="react-image-crop", version="11.0.6") @JsModule("./src/image-crop.tsx") @Tag("image-crop") @CssImport("react-image-crop/dist/ReactCrop.css") @CssImport("./styles/image-crop-styles.css") public class ImageCrop extends ReactAdapterComponent
Component for cropping images based on react-image-crop library. This component allows users to define and manipulate crop areas on images.
Author:
Paola De Bartolo / Flowing Code
See Also:
  • Constructor Details

    • ImageCrop

      public ImageCrop(String src)
      Constructs an ImageCrop component with the given image URL.
      Parameters:
      src - the URL of the image to be cropped
    • ImageCrop

      @Deprecated(forRemoval=true, since="1.2.0") public ImageCrop(Image image)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This constructor only preserves the image URL and alternate text. Use ImageCrop(String) instead.
      Constructs an ImageCrop component with the given image.
      Parameters:
      image - the image to be cropped
  • Method Details

    • addCroppedImageListener

      protected Registration addCroppedImageListener(ComponentEventListener<CroppedImageEvent> listener)
      Adds a listener for the CroppedImageEvent fired when the cropped image is updated.
      Parameters:
      listener - the listener to be added
      Returns:
      a registration for the listener, which can be used to remove the listener
    • setImageSrc

      public void setImageSrc(String imageSrc)
      Sets the source of the image to be cropped.
      Parameters:
      imageSrc - the image source
    • getImageSrc

      public String getImageSrc()
      Gets the source of the image being cropped.
      Returns:
      the image source
    • setImageAlt

      public void setImageAlt(String imageAlt)
      Sets the alternative information of the image to be cropped.
      Parameters:
      imageAlt - the image alternative information
    • getImageAlt

      public String getImageAlt()
      Gets the alternative information of the image being cropped.
      Returns:
      the image alternative information
    • setCrop

      public void setCrop(Crop crop)
      Defines the crop dimensions.
      Parameters:
      crop - the crop dimensions
    • getCrop

      public Crop getCrop()
      Gets the crop dimensions.
    • setAspect

      public void setAspect(double aspect)
      Sets the aspect ratio of the crop. For example, 1 for a square or 16/9 for landscape.
      Parameters:
      aspect - the aspect ratio of the crop
    • getAspect

      public double getAspect()
      Gets the aspect ratio of the crop.
      Returns:
      the aspect ratio
    • setCircularCrop

      public void setCircularCrop(boolean circularCrop)
      Sets whether the crop area should be shown as a circle. If the aspect ratio is not 1, the circle will be warped into an oval shape. Defaults to false.
      Parameters:
      circularCrop - true to show the crop area as a circle, false otherwise
    • isCircularCrop

      public boolean isCircularCrop()
      Gets whether the crop area is shown as a circle.
      Returns:
      true if the crop area is a circle, false otherwise
    • setKeepSelection

      public void setKeepSelection(boolean keepSelection)
      Sets whether the selection can't be disabled if the user clicks outside the selection area. Defaults to false.
      Parameters:
      keepSelection - true so selection can't be disabled if the user clicks outside the selection area, false otherwise.
    • isKeepSelection

      public boolean isKeepSelection()
      Gets whether the selection is enabled.
      Returns:
      true if the selection is enabled, false otherwise
    • setDisabled

      public void setDisabled(boolean disabled)
      Sets whether the user cannot resize or draw a new crop. Defaults to false.
      Parameters:
      disabled - true to disable crop resizing and drawing, false otherwise
    • isDisabled

      public boolean isDisabled()
      Gets whether the crop resizing and drawing is disabled.
      Returns:
      true if disabled, false otherwise
    • setLocked

      public void setLocked(boolean locked)
      Sets whether the user cannot create or resize a crop, but can still drag the existing crop around. Defaults to false.
      Parameters:
      locked - true to lock the crop, false otherwise
    • isLocked

      public boolean isLocked()
      Gets whether the crop is locked.
      Returns:
      true if the crop is locked, false otherwise
    • setCropMinWidth

      public void setCropMinWidth(Integer minWidth)
      Sets a minimum crop width, in pixels.
      Parameters:
      minWidth - the minimum crop width
    • getCropMinWidth

      public Integer getCropMinWidth()
      Gets the minimum crop width, in pixels.
      Returns:
      the minimum crop width
    • setCropMinHeight

      public void setCropMinHeight(Integer minHeight)
      Sets a minimum crop height, in pixels.
      Parameters:
      minHeight - the minimum crop height
    • getCropMinHeight

      public Integer getCropMinHeight()
      Gets the minimum crop height, in pixels.
      Returns:
      the minimum crop height
    • setCropMaxWidth

      public void setCropMaxWidth(Integer maxWidth)
      Sets a maximum crop width, in pixels.
      Parameters:
      maxWidth - the maximum crop width
    • getCropMaxWidth

      public Integer getCropMaxWidth()
      Gets the maximum crop width, in pixels.
      Returns:
      the maximum crop width
    • setCropMaxHeight

      public void setCropMaxHeight(Integer maxHeight)
      Sets a maximum crop height, in pixels.
      Parameters:
      maxHeight - the maximum crop height
    • getCropMaxHeight

      public Integer getCropMaxHeight()
      Gets the maximum crop height, in pixels.
      Returns:
      the maximum crop height
    • setRuleOfThirds

      public void setRuleOfThirds(boolean ruleOfThirds)
      Sets whether to show rule of thirds lines in the cropped area. Defaults to false.
      Parameters:
      ruleOfThirds - true to show rule of thirds lines, false otherwise
    • isRuleOfThirds

      public boolean isRuleOfThirds()
      Gets whether rule of thirds lines are shown in the cropped area.
      Returns:
      true if rule of thirds lines are shown, false otherwise
    • getCroppedImageDataUri

      public String getCroppedImageDataUri()
      Returns the cropped image data URI.
      Returns:
      the cropped image data URI
    • setImageFullHeight

      public void setImageFullHeight(Boolean fullHeight)
      Sets the image to occupy the full viewport height when enabled. If fullHeight is true, applies a CSS class that sets the image height to 100vh. If false, removes the class to revert to the default height.
      Parameters:
      fullHeight - whether the image should fill the viewport height
    • getCroppedImageBase64

      public byte[] getCroppedImageBase64()
      Decodes the cropped image data URI and returns it as a byte array. If the image data URI is not in the format "data:image/*;base64,", it will be decoded assuming it is a Base64 encoded string.

      This method incorporates work licensed under MIT. Copyright 2021-2023 David "F0rce" Dodlek https://github.com/F0rce/cropper

      Returns:
      byte[] the decoded byte array of the cropped image