shadcn.io is not affiliated with official shadcn/ui
Crop Tool File Upload Block for Svelte
A numeric crop panel: a drawn listing photo in the image cropper beside X, Y, Width and Height boxes that stay in step with the frame, a ratio lock, aspect presets, and readouts for the share kept and the estimated size.
Installation
Overview
Set a crop to exact pixels instead of by eye, with this image crop panel for Svelte with Ark UI. It is the editor of Framecut, a listing-photo tool. A drawn 2400 by 1600 house sits in the Image Cropper at the start of a framed panel, and X, Y, Width and Height Inputs sit at the end, two by two. Drag the frame or pull a handle and the numbers follow; type a number and the frame moves. A Switch locks the frame's ratio, a Toggle Group sets it to Free, 1:1, 4:3, 3:2 or 16:9, and one button crops to 1080 by 1080, centred. Two readouts are worked out from the frame: the share of the photo it keeps and an estimated file size, the typed 3.0 MB original times that share. Apply crop puts the frame in the status line; Reset brings back the first one. The panel is ruled by Guides and the one primary is the Shine Button. For listing photos, product shots and any upload that is cropped to a spec.
FAQ
How do the boxes and the frame stay in step?
The cropper reports its frame in its own pixels whenever it moves; the block turns that into pixels of the 2400 by 1600 photo and shows it in the boxes. Typing a valid number goes the other way: the block works out the new frame, then seats the cropper again at that frame. A number outside its range (for example a Width over 2400) is refused with the range in the status line and the frame stays where it was.
What does the ratio lock do?
With the lock on, the frame keeps its shape: change Width and Height follows, change Height and Width follows, and the frame is trimmed to fit the photo. The presets set the lock to a ratio; Free turns it off. Dragging a handle with a ratio set keeps the shape too, because the cropper holds it.
How is the estimated size worked out?
It is the typed original size, 3.0 MB, times the share of the photo's area the frame keeps. It is arithmetic on a typed number, not a measurement: a real file depends on the format and how busy the picture is.
What stays local in the demo, and how do I wire it up?
Everything. The photo is a drawing passed to the cropper as an inline SVG, no file is read, and Apply crop only writes the frame into the status line. In your app pass the picked image to the cropper, read the frame in photo pixels as the block does, and crop on a canvas or on your server with those four numbers.