Package de.f0rce.cropper.settings
Class CropperSettings
java.lang.Object
de.f0rce.cropper.settings.CropperSettings
public class CropperSettings
extends java.lang.Object
Define settings for the
Cropper
, which can be applied via the
Cropper(CropperSettings, String, String)
constructor.- Author:
- David "F0rce" Dodlek
-
Constructor Summary
Constructors Constructor Description CropperSettings()
-
Method Summary
Modifier and Type Method Description void
setAspectRatio(double aspectRatio)
Define the fixed aspect ratio of the crop box.void
setAutoCrop(boolean autoCrop)
Enable to crop the image automatically when initialized.
Default:true
void
setAutoCropArea(double autoCropArea)
It should be a number between 0 and 1.void
setBackground(boolean background)
Show the grid background of the container.
Default:true
void
setCenter(boolean center)
Show the center indicator above the crop box.
Default:true
void
setCheckCrossOrigin(boolean checkCrossOrigin)
Check if the current image is a cross-origin image.
If so, acrossOrigin
attribute will be added to the cloned image element, and a timestamp parameter will be added to thesrc
attribute to reload the source image to avoid browser cache error.
Adding acrossOrigin
attribute to the image element will stop adding a timestamp to the image URL and stop reloading the image.void
setCheckOrientation(boolean checkOrientation)
Check the current image's Exif Orientation information.void
setCropBoxMovable(boolean cropBoxMovable)
Enable to move the crop box by dragging.
Default:true
void
setCropBoxResizable(boolean cropBoxResizable)
Enable to resize the crop box by dragging.
Default:true
void
setCroppedImageHeight(int croppedImageHeight)
Sets the height of the cropped image.
Default:4096
void
setCroppedImageWidth(int croppedImageWidth)
Sets the width of the cropped image.
Default:4096
void
setDragMode(DragMode dragMode)
Define the dragging mode of the cropper.
Default:DragMode.crop
Options:
-DragMode.crop
: creates a new crop box
-DragMode.move
: move the canvas
-DragMode.none
: do nothingvoid
setGuides(boolean guides)
Show the dashed lines above the crop box.
Default:true
void
setHighlight(boolean highlight)
Show the white modal above the crop box (highlight the crop box).
Default:true
void
setInitialAspectRatio(double initialAspectRatio)
Define the initial aspect ratio of the crop box.void
setMinCanvasHeight(int minCanvasHeight)
The minimum height of the canvas (image wrapper).
Default:0
void
setMinCanvasWidth(int minCanvasWidth)
The minimum width of the canvas (image wrapper).
Default:0
void
setMinContainerHeight(int minContainerHeight)
The minimum height of the container.
Default:100
void
setMinContainerWidth(int minContainerWidth)
The minimum width of the container.
Default:200
void
setMinCropBoxHeight(int minCropBoxHeight)
The minimum height of the crop box.
Note: This size is relative to the page, not the image.
Default:0
void
setMinCropBoxWidth(int minCropBoxWidth)
The minimum width of the crop box.
Note: This size is relative to the page, not the image.
Default:0
void
setModal(boolean modal)
Show the black modal above the image and under the crop box.
Default:true
void
setMovable(boolean movable)
Enable to move the image.
Default:true
void
setResponsive(boolean responsive)
Re-render the cropper when resizing the window.
Default:true
void
setRestore(boolean restore)
Restore the cropped area after resizing the window.
Default:true
void
setRotatable(boolean rotatable)
Enable to rotate the image.
Default:true
void
setRoundCropBox(boolean roundCropBox)
Sets the crop box of the cropper to be round.void
setScalable(boolean scalable)
Enable to scale the image.
Default:true
void
setToogleDragModeOnDblclick(boolean toogleDragModeOnDblclick)
Enable to toggle drag mode between"crop"
and"move"
when clicking twice on the cropper.
Default:true
void
setViewMode(ViewMode viewMode)
Define the view mode of the cropper.void
setWheelZoomRatio(double wheelZoomRatio)
Define zoom ratio when zooming the image by mouse wheeling.
Default:0.1
void
setZoomable(boolean zoomable)
Enable to zoom the image.
Default:true
void
setZoomOnTouch(boolean zoomOnTouch)
Enable to zoom the image by dragging touch.
Default:true
void
setZoomOnWheel(boolean zoomOnWheel)
Enable to zoom the image by mouse wheeling.
Default:true
java.lang.String
toJSON()
Turns the settings into an JSON Object which will be sent to the frontend as soon as cropper gets initialized.
-
Constructor Details
-
CropperSettings
public CropperSettings()
-
-
Method Details
-
setViewMode
Define the view mode of the cropper. If you setviewMode
toViewMode.ZERO
the crop box can extend outside the canvas, while a value ofViewMode.ONE
,ViewMode.TWO
orViewMode.THREE
will restrict the crop box to the size of the canvas.viewMode
ofViewMode.TWO
orViewMode.THREE
will additionally restrict the canvas to the container. There is no difference betweenViewMode.TWO
andViewMode.THREE
when the proportions of the canvas and the container are the same.
Default:ViewMode.ZERO
Options:
-ViewMode.ZERO
: no restrictions
-ViewMode.ONE
: restrict the crop box not to exceed the size of the canvas.
-ViewMode.TWO
: restrict the minimum canvas size to fit within the container. If the proportions of the canvas and the container differ, the minimum canvas will be surrounded by extra space in one of the dimensions.
-ViewMode.THREE
: restrict the minimum canvas size to fill fit the container. If the proportions of the canvas and the container are different, the container will not be able to fit the whole canvas in one of the dimensions.- Parameters:
viewMode
-ViewMode
-
setDragMode
Define the dragging mode of the cropper.
Default:DragMode.crop
Options:
-DragMode.crop
: creates a new crop box
-DragMode.move
: move the canvas
-DragMode.none
: do nothing- Parameters:
dragMode
-DragMode
-
setInitialAspectRatio
public void setInitialAspectRatio(double initialAspectRatio)Define the initial aspect ratio of the crop box. By default, it is the same as the aspect ratio of the canvas (image wrapper).
Default:0
(interpreted as null/NaN by frontend)
Only availible when thesetAspectRatio(double)
option is set to 0.
Example:
CropperSettings cropperSettings = new CropperSettings(); cropperSettings.setAspectRatio(0); // optional cropperSettings.setInitialAspectRatio(16.0 / 9.0); // make sure to add the .0 to get the correct result
- Parameters:
initialAspectRatio
- int
-
setAspectRatio
public void setAspectRatio(double aspectRatio)Define the fixed aspect ratio of the crop box. By default, the crop box has a free ratio.
Default:0
(interpreted as null/NaN by frontend)
Example:
CropperSettings cropperSettings = new CropperSettings(); cropperSettings.setAspectRatio(16.0 / 9.0); // make sure to add the .0 to get the correct result
- Parameters:
aspectRatio
- int
-
setResponsive
public void setResponsive(boolean responsive)Re-render the cropper when resizing the window.
Default:true
- Parameters:
responsive
- boolean
-
setRestore
public void setRestore(boolean restore)Restore the cropped area after resizing the window.
Default:true
- Parameters:
restore
- boolean
-
setCheckCrossOrigin
public void setCheckCrossOrigin(boolean checkCrossOrigin)Check if the current image is a cross-origin image.
If so, acrossOrigin
attribute will be added to the cloned image element, and a timestamp parameter will be added to thesrc
attribute to reload the source image to avoid browser cache error.
Adding acrossOrigin
attribute to the image element will stop adding a timestamp to the image URL and stop reloading the image. But the request (XMLHttpRequest) to read the image data for orientation checking will require a timestamp to bust cache to avoid browser cache error. You can set thesetCheckOrientation(boolean)
option tofalse
to cancel this request.
If the value of the image'scrossOrigin
attribute is"use-credentials"
, then thewithCredentials
attribute will set totrue
when read the image data by XMLHttpRequest.
Default:true
- Parameters:
checkCrossOrigin
- boolean
-
setCheckOrientation
public void setCheckOrientation(boolean checkOrientation)Check the current image's Exif Orientation information. Note that only a JPEG image may contain Exif Orientation information.
Exactly, read the Orientation value for rotating or flipping the image, and then override the Orientation value with 1 (the default value) to avoid some issues on iOS devices.
Requires to set both thesetRotatable(boolean)
andsetScalable(boolean)
options totrue
at the same time.
Note: Do not trust this all the time as some JPG images may have incorrect (non-standard) Orientation values
Default:true
- Parameters:
checkOrientation
- boolean
-
setModal
public void setModal(boolean modal)Show the black modal above the image and under the crop box.
Default:true
- Parameters:
modal
- boolean
-
setGuides
public void setGuides(boolean guides)Show the dashed lines above the crop box.
Default:true
- Parameters:
guides
- boolean
-
setCenter
public void setCenter(boolean center)Show the center indicator above the crop box.
Default:true
- Parameters:
center
- boolean
-
setHighlight
public void setHighlight(boolean highlight)Show the white modal above the crop box (highlight the crop box).
Default:true
- Parameters:
highlight
- boolean
-
setBackground
public void setBackground(boolean background)Show the grid background of the container.
Default:true
- Parameters:
background
- boolean
-
setAutoCrop
public void setAutoCrop(boolean autoCrop)Enable to crop the image automatically when initialized.
Default:true
- Parameters:
autoCrop
- boolean
-
setAutoCropArea
public void setAutoCropArea(double autoCropArea)It should be a number between 0 and 1. Define the automatic cropping area size (percentage).
Default:0.8
(80% of the image)- Parameters:
autoCropArea
- double
-
setMovable
public void setMovable(boolean movable)Enable to move the image.
Default:true
- Parameters:
movable
- boolean
-
setRotatable
public void setRotatable(boolean rotatable)Enable to rotate the image.
Default:true
- Parameters:
rotatable
- boolean
-
setScalable
public void setScalable(boolean scalable)Enable to scale the image.
Default:true
- Parameters:
scalable
- boolean
-
setZoomable
public void setZoomable(boolean zoomable)Enable to zoom the image.
Default:true
- Parameters:
zoomable
- boolean
-
setZoomOnTouch
public void setZoomOnTouch(boolean zoomOnTouch)Enable to zoom the image by dragging touch.
Default:true
- Parameters:
zoomOnTouch
- boolean
-
setZoomOnWheel
public void setZoomOnWheel(boolean zoomOnWheel)Enable to zoom the image by mouse wheeling.
Default:true
- Parameters:
zoomOnWheel
- boolean
-
setWheelZoomRatio
public void setWheelZoomRatio(double wheelZoomRatio)Define zoom ratio when zooming the image by mouse wheeling.
Default:0.1
- Parameters:
wheelZoomRatio
- double
-
setCropBoxMovable
public void setCropBoxMovable(boolean cropBoxMovable)Enable to move the crop box by dragging.
Default:true
- Parameters:
cropBoxMovable
- boolean
-
setCropBoxResizable
public void setCropBoxResizable(boolean cropBoxResizable)Enable to resize the crop box by dragging.
Default:true
- Parameters:
cropBoxResizable
- boolean
-
setToogleDragModeOnDblclick
public void setToogleDragModeOnDblclick(boolean toogleDragModeOnDblclick)Enable to toggle drag mode between"crop"
and"move"
when clicking twice on the cropper.
Default:true
- Parameters:
toogleDragModeOnDblclick
- boolean
-
setMinContainerWidth
public void setMinContainerWidth(int minContainerWidth)The minimum width of the container.
Default:200
- Parameters:
minContainerWidth
- int
-
setMinContainerHeight
public void setMinContainerHeight(int minContainerHeight)The minimum height of the container.
Default:100
- Parameters:
minContainerHeight
- int
-
setMinCanvasWidth
public void setMinCanvasWidth(int minCanvasWidth)The minimum width of the canvas (image wrapper).
Default:0
- Parameters:
minCanvasWidth
- int
-
setMinCanvasHeight
public void setMinCanvasHeight(int minCanvasHeight)The minimum height of the canvas (image wrapper).
Default:0
- Parameters:
minCanvasHeight
- int
-
setMinCropBoxWidth
public void setMinCropBoxWidth(int minCropBoxWidth)The minimum width of the crop box.
Note: This size is relative to the page, not the image.
Default:0
- Parameters:
minCropBoxWidth
- int
-
setMinCropBoxHeight
public void setMinCropBoxHeight(int minCropBoxHeight)The minimum height of the crop box.
Note: This size is relative to the page, not the image.
Default:0
- Parameters:
minCropBoxHeight
- int
-
setCroppedImageHeight
public void setCroppedImageHeight(int croppedImageHeight)Sets the height of the cropped image.
Default:4096
- Parameters:
croppedImageHeight
- int
-
setCroppedImageWidth
public void setCroppedImageWidth(int croppedImageWidth)Sets the width of the cropped image.
Default:4096
- Parameters:
croppedImageWidth
- int
-
setRoundCropBox
public void setRoundCropBox(boolean roundCropBox)Sets the crop box of the cropper to be round.- Parameters:
roundCropBox
- boolean
-
toJSON
public java.lang.String toJSON()Turns the settings into an JSON Object which will be sent to the frontend as soon as cropper gets initialized.- Returns:
String
-