jimp-dev / jimp-dev/jimp

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

Open
#801 1 comment 0 reactions 0 assignees View on GitHub
enhancement help wanted solution in issue
Dominant language
TypeScript
Stars
14.7k
Forks
777
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I'm generating texture atlasses from other smaller images. I would like to crop the smaller images from surrounding transparency, which `.autocrop()` does fine, but I would need the X and Y coordinates of the cropped image relative to its original size.

**Describe the solution you'd like**
Since `.autocrop()` returns image instance, it can't return the coordinates, so maybe cropped instances could have `.cropX, .cropY, .cropWidth, .cropHeight` properties? Anything that would give me the crop X and Y coords will be fine (without scanning the images again).

Alternatively, there could be a new method, maybe named `boundingBox()` or something. This new method would return crop coordinates and size without cropping the image. That method would need to do the same calculations and accept the same arguments as `.autocrop()`. The result of the new `.boundingBox()` call could be passed to the `.crop(x, y, w, h)` method to do actual cropping.

**Describe alternatives you've considered**
I don't see a way with current API to get the crop coords.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing autocrop() and crop(x, y, w, h) APIs to understand their current arguments and return behavior. Choose an API that exposes the crop coordinates without rescanning the image and preserves the existing cropping workflow; done means callers can obtain X, Y, width, and height and use them for cropping.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.