Support enlargement when using embed option (was: Possible error with embed())
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 32.7k
- Forks
- 1.4k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
Unsure if this is on sharp's end, or possibly within libvips. The issue is that when attempting to resize(w,h).embed() an image which has either a width or height lower than w or h respectively, the embed() call simply never gets hit, and you get the full image returned.
For example, with an image that is 200x200, if I do:
resize(100, 150).embed() - works fine, you get a 100x150 image, with vertical padding.
resize(150, 100).embed() - works fine, you get a 150x100 image, with horizontal padding.
resize(200, 150).embed() - works fine, you get a 200x150 image, with horizontal padding (2 param = image width)
However:
resize(201, 150).embed() - returns original image.
resize(150, 201).embed() - returns original image.
resize(220, 220).embed() - returns original image.
This is also noticeable if you have images with much larger widths than heights, say, a logo. If I want to ensure they come back as 200x200, then this returns the original image on most scenarios (h is very small, almost always less than 200, even if the width is generally greater than 200).
Is this expected behavior? I understand we never want to attempt to enlarge an image for obvious reasons. However, since we're padding the images with some background, the issue of quality loss becomes less likely.
In some of the scenarios I'm running into, there's enough width to the images I'm attempting to resize for them to simply receive vertical padding, but whatever's checking the dimensions seems to cut through and just return the original instead. Even if both the width/height passed to resize are larger than the image's dimensions, could both vertical and horizontal paddings be added?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the listed resize(...).embed() cases through sharp's JavaScript API, comparing dimensions that are equal to or larger than the source. Trace where enlargement is rejected and determine whether padding should still produce the requested dimensions; done means the reported cases have defined behavior and regression coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- computer-vision
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100