Image crop
Frame an image in a rectangle or a circle of a fixed aspect, by dragging, pinching, the wheel or the keyboard, and export the framed part at a chosen size as a Blob or a data URL. The piece between ray-file-upload (or an <input type=file>) and ray-avatar.
—
API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-image-crop> · RayImageCrop
The image always covers the frame: at zoom 1 it fits the frame's short side, and it cannot be moved so far that a gap shows. The framing is read and set as crop, a rectangle in pixels of the original, so it can be saved, reopened or applied elsewhere. The image is decoded once into a reduced working copy (as many pixels as the output, or the stage on screen, need at max-zoom) and the full-size decode is released; toBlob and toDataURL draw from that copy. EXIF orientation is applied, as in an <img>. Styling: --ray-image-crop-inset (the dimmed margin around the frame, default --ray-space-4), --ray-image-crop-dim (its color) and --ray-image-crop-max-height (default 70vh).
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
src | src | string | The image: a URL, or (as a property) a File or Blob, such as the one an <input type=file> gives. A cross-origin URL needs CORS to be exportable. A HostFile (the paths of ray-file-upload native) has no bytes: read it in the program and pass a URL. | |
aspect | aspect reflects | string | 1 | Width / height of the frame and of the output: "1", "16/9", "4:3", "1.5". |
shape | shape reflects | rect | circle | rect | The frame's mask. circle (an ellipse when the aspect is not 1) only masks: the output is still the rectangle, for ray-avatar to round. |
zoom | zoom | number | 1 | 1: the image covers the frame; 2: twice as close. Kept between min-zoom and max-zoom; the user changes it. |
minZoom | min-zoom | number | 1 | The least zoom (1 or more: the image always covers the frame). |
maxZoom | max-zoom | number | 4 | The most zoom. It also sets how many pixels the working copy keeps. |
zoomControl | zoom-control reflects | boolean | A zoom slider under the image (the wheel, pinch and + / - zoom in any case). | |
outputSize | output-size | string | 512 | Size of the exported image: a width ("320", the height from the aspect) or "640x360". |
type | type | string | image/jpeg | Format of toBlob/toDataURL. A browser that cannot encode it gives PNG (Safari has no WebP encoder). |
quality | quality | number | 0.85 | 0…1, for image/jpeg and image/webp. |
label | label | string | Crop image (text image-crop.label) | Accessible name of the image area. |
zoomLabel | zoom-label | string | Zoom (text image-crop.zoom) | Name of the zoom slider, and the word of the announced zoom ("Zoom 150%"). |
disabled | disabled reflects | boolean | No moving nor zooming. |
| Event | Description |
|---|---|
input | The framing moved (every step of a drag, pinch, wheel or the slider). |
change | The framing settled: pointer released, a key pressed, the slider released or the wheel stopped (read crop, zoom). |
ray-load | The image loaded (its original size). |
ray-error | The image could not be loaded or decoded. |
| Part | Description |
|---|---|
stage | The image area (focusable; role slider for the zoom). |
image | The image (a canvas of the working copy). |
frame | The frame; what lies outside it is dimmed. |
zoom | The zoom ray-slider (with zoom-control). |
Texts
What it writes itself, in English; setStrings() translates them (Getting started: Languages).
| Key | English |
|---|---|
image-crop.label | Crop image |
image-crop.zoom | Zoom |