shadcn.io is not affiliated with official shadcn/ui
Resize Image File Upload Block for React
A resize panel with Width and Height boxes, a keep-the-ratio switch and four presets, a to-scale drawing of the old and new boxes, the percentages, and a derived ImageMagick command with Copy.
Installation
Overview
See what a new size does to an image before you run anything, with this resize panel for React with Base UI. It is the prep tool of Inchworm, for a tile retailer's catalogue. To the start, a drawing at one scale: the original as a dashed 3000 by 2000 box and the new size as a solid box over it, with the share of the width and of the pixels worked out under it and a line that says when the new size is larger than the original or a different shape. To the end, Width and Height Inputs, a Switch to keep the ratio (change one side and the other follows), and four presets: Thumbnail 150, Social 1200 by 630, HD 1920 by 1080 and 4K 3840. Under the drawing sits the derived ImageMagick command in a read-only Input Group with a Copy Button. Name your own file lends its name to the command. The panel is ruled by Guides. For catalogues, galleries and any pipeline that sets image sizes.
FAQ
How does keeping the ratio work?
With the switch on, the other side is worked out from the original's 3 to 2 shape and rounded to a whole pixel, as you type. Switch it off and each side is its own. Choosing a preset with another shape, such as Social 1200 by 630, turns the switch off, and the status line says so.
Is the drawing really to scale?
Yes. Both boxes are drawn with one scale factor chosen so the larger of the two fits the frame, so a 4K size shows as a box bigger than the dashed original and the percentages match what you see.
What is the command?
magick, the file name, -resize with the width and height, and an output name. It adds a ! when the size is not the original's shape, which tells ImageMagick to use the exact size. Copy puts it on your clipboard; the block never runs it.
What happens when I name my own file?
Its name and size go into the command and the caption. Its pixel size is not read, so the drawing keeps the sample's 3000 by 2000, and the caption says so. A file that is not an image is refused with a line in the status.