Skip to content

feat(image-studio): crop, auto-frame and model preview (T-M3) - #460

Merged
lightningpixel merged 9 commits into
devfrom
feat/image-crop-pad
Nov 17, 2026
Merged

lightningpixel merged 9 commits into
devfrom
feat/image-crop-pad

Conversation

@lightningpixel

Copy link
Copy Markdown
Owner

Closes #422

What

  • Crop: four edge sliders (0–45% each). Transparency is kept.
  • Auto-frame: finds the subject from its transparency, centres it in a square and scales it to fill the frame. You set the margin (10% by default) and the resolution (512–2048). An image with no transparency, or a fully opaque RGBA one, gets "remove the background first".
  • What the model sees: a canvas toggle that shows the exact file sent to the generator, with its size in pixels and a warning when it is not square.
  • Only one image op runs at a time, so a fast op can no longer clear the spinner of a running one.

Review fixes for code merged in #457

These are separate commits on this branch, because they touch the same files.

  • Security: /image/op/* now only reads files inside the workspace, checked after resolving the path, so .. and symlinks pointing out are refused too. Anything else gets a 403. When an image was opened from elsewhere, the renderer copies it into <workspace>/Images through Electron and runs the op on the copy.
  • Params changed during the setup download are used when the op runs.
  • A mask that is hidden and shown again no longer renders a revoked blob URL.
  • The prepare endpoint docstring now says POST only, and the requirements type matches what describe() returns.

Tests

npm run lint, npm run test (Python 532 OK, JS 0 failures) and npm run build pass. Not yet tested by hand in the app.

Crop trims a percentage off each edge. Auto-frame recenters the subject
on its alpha bounding box and pads it to a transparent square at a chosen
resolution with a uniform margin, so generators get a framed input
instead of cropping it each their own way.
A canvas toggle shows the selected file exactly as Generate uploads it, at
its own resolution with its edges outlined, and says when it is not square.
Crop's four edges sit in two columns in the toolbar.
…o-frame

Auto-frame now refuses an image whose alpha channel has no transparent
pixel (clipboard pastes, screenshots) instead of letterboxing the whole
picture. RGB and L PNGs with a tRNS colour key count as transparent, so
crop keeps their transparency and auto-frame accepts them. Crop checks
the mode and info only, and auto-frame reads the uint8 alpha directly.
The ops share the canvas busy overlay, so a fast op finishing (Crop)
cleared it while Remove background was still running. A shared run lock
now lets one op run at a time and disables the others meanwhile.
POST /image/op/{op} read any absolute path on disk. The input is now
resolved (collapsing `..` and following symlinks) and refused with 403
`outside_workspace` unless it lies inside the workspace. The Image Studio
copies an image opened from elsewhere into <workspace>/Images once and
runs the op on that copy.
…download

The op the user asked for runs once the one-time download finishes. It
used the params captured when Download was clicked, so changes made
during the install were ignored; it now reads them when it starts.
Hiding the mask revoked its object URL but kept it in state, so showing
the same mask again displayed a broken image. The state is now cleared
with the URL.
…s them

GET /image/ops returns each requirement as {kind, id, label}, not a string.
@lightningpixel
lightningpixel merged commit 57af031 into dev Nov 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant