|
| 1 | +--- |
| 2 | +title: "Image Cropper" |
| 3 | +url: /appstore/widgets/image-cropper/ |
| 4 | +description: "Describes the configuration and usage of the Image Cropper widget, which is available in the Mendix Marketplace." |
| 5 | +#If moving or renaming this doc file, implement a temporary redirect and let the respective team know they should update the URL in the product. See Mapping to Products for more details. |
| 6 | +--- |
| 7 | + |
| 8 | +## Introduction |
| 9 | + |
| 10 | +The [Image Cropper](https://marketplace.mendix.com/link/component/302076) widget lets an end-user crop, rotate, zoom, and convert an image to grayscale directly in the browser. The edited result is saved back to the same image attribute the widget is bound to. |
| 11 | + |
| 12 | +All editing is done client-side on an HTML canvas. There is no separate apply or save button: the crop is saved back to the image attribute automatically as the end-user works. |
| 13 | + |
| 14 | +{{% alert color="info" %}} |
| 15 | +This widget replaces the legacy [Image Crop](/appstore/modules/image-crop/) module. |
| 16 | +{{% /alert %}} |
| 17 | + |
| 18 | +{{< figure src="/attachments/appstore/platform-supported-content/widgets/image-cropper/image-cropper-demo.gif" alt="Cropping an image with a rectangular crop shape" class="no-border" >}} |
| 19 | + |
| 20 | +### Features |
| 21 | + |
| 22 | +- Crop with a rectangular or circular crop shape |
| 23 | +- Constrain the crop to a fixed aspect ratio (1:1, 16:9, 4:3, 3:4), a custom ratio, or a free selection |
| 24 | +- Zoom with a slider and/or the mouse wheel |
| 25 | +- Rotate the image in 90-degree increments |
| 26 | +- Convert the image to grayscale |
| 27 | +- Reset the image back to its original state |
| 28 | +- Save the result as PNG or JPEG at the source or on-screen resolution |
| 29 | +- Trigger a Mendix action each time the crop is applied |
| 30 | + |
| 31 | +### Limitations |
| 32 | + |
| 33 | +- The widget requires an editable image attribute and both reads from and writes to that same attribute. There is no separate output attribute. |
| 34 | +- Editing operations do not save back to a read-only image attribute. |
| 35 | +- The widget is available on the web platform only and is not offline capable. |
| 36 | + |
| 37 | +## Configuration |
| 38 | + |
| 39 | +The following sections will describe the different available widget properties and configurations. |
| 40 | + |
| 41 | +### General Tab {#general} |
| 42 | + |
| 43 | +#### Source Section |
| 44 | + |
| 45 | +The **Source** section (required) is used to configure the image the widget edits. It has the following property: |
| 46 | + |
| 47 | +- **Image attribute** – Specifies the image the end-user wants to crop. |
| 48 | + - The cropped result is saved back to this same attribute. |
| 49 | + - The attribute is both the source and the destination for the widget. |
| 50 | + |
| 51 | +#### Crop Area Section |
| 52 | + |
| 53 | +The **Crop area** section is used to configure the shape and proportions of the crop selection. It includes the following properties: |
| 54 | + |
| 55 | +* **Crop shape** – Defines the shape of the crop. |
| 56 | + * **Rectangle** (default) – When enabled, the full crop rectangle is saved. |
| 57 | + * **Circle** – When enabled, the corners are masked and the saved image is clipped to an ellipse inscribed in the crop rectangle. |
| 58 | +- **Aspect ratio** – Locks the crop proportions. |
| 59 | + * **Free** (default) – The end-user can resize the selection to any proportion. |
| 60 | + * **1:1**, **16:9**, **4:3**, or **3:4** – When set to one of these predetermined ratios, the selection is locked to that ratio during resize. |
| 61 | + * **Custom** – When enabled, the selection is locked to the ratio defined by **Custom aspect width** and **Custom aspect height**. |
| 62 | +- **Custom aspect width** (default **1**) – The width side of the ratio (for example, _3_ in 3:2). |
| 63 | + - Configurable when **Aspect ratio** is set to **Custom**. |
| 64 | + - When either the custom width or custom height is not greater than _0_, the selection falls back to a free-form shape. |
| 65 | +- **Custom aspect height** (default **1**) – The height side of the ratio (for example, _2_ in 3:2). |
| 66 | + - Configurable when **Aspect ratio** is set to **Custom**. |
| 67 | + - When either the custom width or custom height is not greater than _0_, the selection falls back to a free-form shape. |
| 68 | + |
| 69 | +{{< figure src="/attachments/appstore/platform-supported-content/widgets/image-cropper/image-cropper-circle-demo.gif" alt="Cropping an image with a circular crop shape" class="no-border" >}} |
| 70 | + |
| 71 | +#### Events Section |
| 72 | + |
| 73 | +The **Events** section allows you to configure what happens each time the crop is applied. It includes the following property: |
| 74 | + |
| 75 | +- **On crop** (optional) – A Mendix action that runs each time the crop is auto-applied to the image attribute. |
| 76 | + - The action runs after a crop is saved back, but not after a rotation or a reset. |
| 77 | + |
| 78 | +### Dimensions Tab {#dimensions} |
| 79 | + |
| 80 | +#### Canvas Section |
| 81 | + |
| 82 | +The **Canvas** section is used to configure the on-screen size of the crop area. It includes the following properties: |
| 83 | + |
| 84 | +- **Canvas max width (px)** (default **800**) – Sets the maximum on-screen width of the crop area. |
| 85 | + - The image scales down to fit, and the canvas wraps the rendered image so that smaller crops produce a smaller canvas with no blank gaps. |
| 86 | + - This property does not change the saved image size. |
| 87 | +- **Canvas max height (px)** (default **800**) – the maximum on-screen height of the crop area. |
| 88 | + - The image scales down to fit, and the canvas wraps the rendered image so that smaller crops produce a smaller canvas with no blank gaps. |
| 89 | + - This property does not change the saved image size. |
| 90 | + |
| 91 | +### Behavior Tab {#behavior} |
| 92 | + |
| 93 | +#### Interaction Section |
| 94 | + |
| 95 | +The **Interaction** section is used to configure how the end-user interacts with the crop selection. It includes the following property: |
| 96 | + |
| 97 | +- **Resizable handles** (default **Yes**) – Allows the end-user to resize the selection by dragging its corners. |
| 98 | + - When set to **No**, the selection cannot be resized by dragging its corners. |
| 99 | + |
| 100 | +#### Buttons Section |
| 101 | + |
| 102 | +The **Buttons** section is used to configure the editing buttons shown in the toolbar. It includes the following properties: |
| 103 | + |
| 104 | +- **Enable rotation** (default **Yes**) – Shows rotate-left and rotate-right buttons that rotate the image in 90-degree increments. |
| 105 | + - The rotation is baked into the saved image. |
| 106 | +- **Enable grayscale** (default **No**) – Shows a grayscale toggle. |
| 107 | + - When the toggle is on, the saved image is converted to grayscale (black and white). |
| 108 | +- **Enable reset** (default **Yes**) – Shows a **Reset** button that restores the original image and clears zoom, rotation, and grayscale. |
| 109 | + - The button is available only when the original image could be captured. |
| 110 | + |
| 111 | +#### Zoom Section |
| 112 | + |
| 113 | +The **Zoom** section is used to configure how the end-user zooms the image. It includes the following properties: |
| 114 | + |
| 115 | +- **Enable zoom** (default **Yes**) – The primary switch for zooming. |
| 116 | + - When set to **No**, the slider and mouse-wheel zoom are disabled and the image stays at **1x**. |
| 117 | +- **Show zoom slider** (default **Yes**) – shows the zoom slider below the crop area. |
| 118 | + - Configurable when **Enable zoom** is set to **Yes**. |
| 119 | + - Turn this off to keep mouse-wheel zoom while hiding the slider. |
| 120 | +- **Mouse wheel zoom** (default **On (hold Ctrl)**) – Determines whether the mouse wheel zooms the image. |
| 121 | + - Configurable when **Enable zoom** is set to **Yes**. |
| 122 | + - When set to **On (hold Ctrl)**, the wheel zooms only while <kbd>Ctrl</kbd> is held, so page scroll keeps working. |
| 123 | + - When set to **On**, the wheel always zooms. |
| 124 | + - When set to **Off**, the wheel never zooms. |
| 125 | +- **Minimum zoom** (default **1**) – Sets the smallest zoom level. |
| 126 | + - Configurable when **Enable zoom** is set to **Yes**. |
| 127 | + - A value of _1_ means the image fits the canvas; a value below _1_ lets the end-user zoom out further. |
| 128 | +- **Maximum zoom** (default **4**) – Sets the largest zoom level. |
| 129 | + - Configurable when **Enable zoom** is set to **Yes**. |
| 130 | + - A value of _4_ means the image can be zoomed up to four times the canvas size. |
| 131 | + - This value must be greater than **Minimum zoom**. |
| 132 | + |
| 133 | +### Output Tab {#output} |
| 134 | + |
| 135 | +#### Output Section |
| 136 | + |
| 137 | +The **Output** section is used to configure the format and resolution of the saved image. It includes the following properties: |
| 138 | + |
| 139 | +- **Output format** (default **PNG**) – Sets the file format of the saved image. |
| 140 | + - When set to **PNG**, transparency is preserved and **JPEG quality** is ignored. |
| 141 | + - When set to **JPEG**, a white background is filled behind the image and smaller files are produced. |
| 142 | +- **JPEG quality (0.0 - 1.0)** (default **0.92**) – Sets the JPEG compression level. |
| 143 | + - Configurable when **Output format** is set to **JPEG**. |
| 144 | + - A higher value produces a sharper and larger file. |
| 145 | +- **Output size** (default **Original (source resolution)**) – Sets the resolution of the saved crop. |
| 146 | + - When set to **Original (source resolution)**, the crop is saved at the source resolution of the cropped region, which is the sharpest option. |
| 147 | + - When set to **Viewport (canvas dimensions)**, the crop is saved at the on-screen canvas size. |
| 148 | + |
| 149 | +## Usage |
| 150 | + |
| 151 | +When the widget loads, it shows the image bound to the **Image attribute** with a default crop box centered on the image and covering 80% of it at the configured aspect ratio. If no image is available, the widget shows a **No image** message. |
| 152 | + |
| 153 | +The end-user edits the image as follows: |
| 154 | + |
| 155 | +- **Move or resize the crop box** – The crop is saved immediately when the end-user finishes the drag. |
| 156 | +- **Zoom or toggle grayscale** – The change is saved a short moment after the last adjustment. |
| 157 | +- **Rotate** – A live preview is shown immediately, and the rotation is then saved back to the image attribute. |
| 158 | +- **Reset** – The original image is restored and zoom, rotation, and grayscale are cleared. A reset is not saved as a crop and does not trigger the **On crop** action. |
| 159 | + |
| 160 | +## Styling |
| 161 | + |
| 162 | +The widget is shipped with default styles and works out of the box without Atlas UI. |
| 163 | + |
| 164 | +## Read More |
| 165 | + |
| 166 | +- [Image](/appstore/widgets/image/) |
0 commit comments