shadcn.io is not affiliated with official shadcn/ui
Circular Crop Gallery Block for Vue
A circle cropper with four drawn pictures to pick from and the crop live at three profile-picture sizes, with zoom buttons and a reset.
Installation
Overview
A circular-crop gallery for Vue with Ark UI, for Roundwick, a profile-picture maker. A compact header has a "Picture" toggle at its end with four drawn pictures, each with its subject to one side so the crop matters. Under it a split: a framed image cropper with a circle selection that you drag, resize from its handles, nudge with the arrow keys and zoom with the wheel, with plus and minus, or with the Zoom buttons; and, beyond a divider, the crop live at three sizes (96, 48 and 24 pixels, as a profile page, a comment and a mention show it) with its size in pixels. Reset puts the circle back and clears the zoom. The pictures are drawn greys served to the cropper as SVG data URIs, not photographs: an image cannot read your theme's custom properties, so those few greys are fixed numbers. Nothing is uploaded; the crop only feeds the three previews. It's built from Image Cropper, Toggle Group, Button and Guides. The company is made up for the example.
FAQ
How do I use my own pictures?
Each entry in PICTURES has an id, a label, a description and a src. Replace src with your image's address (or a data URI), keep the description as its alt text, and the cropper and the three previews both use it. Keep the picture square, or change the cropper's aspect-square and the readout, which assumes a square one.
How do I crop with a keyboard?
Tab to the circle, then the arrow keys nudge it (hold Shift for bigger steps) and plus and minus zoom the picture. The Zoom out and Zoom in buttons do the same by pressing, and Reset puts everything back. The cropper's selection announces its position and how to use it for a screen reader.
How do the previews follow the crop?
The cropper sets inline styles on the picture and on the circle as you move them. The block watches those styles, measures the circle against the picture on the next frame and turns the result into three numbers: where the crop starts and how wide it is, as shares of the picture. Each preview is the same picture, scaled and shifted so that crop fills its circle. Nothing is read back from a canvas, so it works with any picture.
How do I get the cropped file?
This demo only previews. To produce a file, read the crop from the cropper's own API (its getCroppedImage returns a blob or a data URL) in your own handler, and upload that.