Skip to content

feat(plugin-crop): add autocropRect helper#1404

Open
Aniketiitk21 wants to merge 2 commits intojimp-dev:mainfrom
Aniketiitk21:codex/autocrop-rect
Open

feat(plugin-crop): add autocropRect helper#1404
Aniketiitk21 wants to merge 2 commits intojimp-dev:mainfrom
Aniketiitk21:codex/autocrop-rect

Conversation

@Aniketiitk21
Copy link
Copy Markdown

@Aniketiitk21 Aniketiitk21 commented May 6, 2026

Summary

  • add image.autocropRect(options) so callers can inspect the exact { x, y, w, h } rectangle that autocrop() would apply
  • refactor autocrop() to reuse the same rectangle calculation logic, keeping the mutating crop behavior aligned with the new helper
  • add plugin-level and public-entrypoint tests so the helper is validated both inside @jimp/plugin-crop and through jimp
  • replace @jimp/plugin-print's shell-specific cp -r build step with a small Node copy script so the wider Jimp build works on Windows too

Why

Today autocrop() can remove borders, but it does not expose the crop rectangle it found. That makes atlas packing, layout alignment, and preflight inspection awkward because consumers have to either rescan the image or mutate it first just to discover the offsets.

This adds a small read-only API that returns the same rectangle autocrop() would use, which means callers can inspect it, store it, or pass it directly into crop().

While validating the change on Windows, the wider jimp... build surfaced a separate portability problem in @jimp/plugin-print: its build script still depended on cp -r. Fixing that keeps the workspace build path consistent across platforms and removes a real validation blocker.

Implementation

  • add autocropRect(options) to @jimp/plugin-crop
  • factor the existing autocrop side-scanning logic into a shared internal helper
  • return the full image bounds when the current options would result in no crop
  • keep autocrop() behavior unchanged by making it consume the same computed rectangle
  • document the helper in the crop plugin README
  • update @jimp/plugin-print to copy its bundled fonts with node:fs/promises.cp() instead of a shell-only cp -r

Validation

  • pnpm exec turbo run build --filter=@jimp/plugin-crop...
  • pnpm exec turbo run test --filter=@jimp/plugin-crop -- --run
  • pnpm --filter @jimp/plugin-crop lint
  • pnpm --filter @jimp/plugin-crop build
  • pnpm --filter jimp test -- --run src/jimp.test.ts
  • pnpm --filter @jimp/plugin-print build
  • pnpm exec turbo run build --filter=jimp...

Closes #801

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.

[Request] Return autocrop() coordinates (cropped area X, Y, W and H)

1 participant