Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: ignore aspect ratio (was "Question: Un-uniform scale possible?") #118

Closed
jsongHBO opened this issue Nov 14, 2014 · 11 comments

Comments

@jsongHBO
Copy link

Hi folks,

How do I resize an image disrespect of aspect ratio and without cropping and embedded padding to the exact size I want?
In gm's term, it'd be resize(width, height, '!');

Thank you

@lovell
Copy link
Owner

lovell commented Nov 14, 2014

This feature is not currently supported, but is now on the TODO list :)

I'm thinking a new "option" method named something like ignoreAspectRatio() would make most sense.

@lovell lovell changed the title Question: Un-uniform scale possible? Feature request: ignore aspect ratio (was "Question: Un-uniform scale possible?") Nov 14, 2014
@bkw
Copy link
Contributor

bkw commented Jan 26, 2015

that would be exactly what I need as well (See dupe #153)

@jcupitt
Copy link
Contributor

jcupitt commented Feb 25, 2015

I haven't supported this feature in vipsthumbnail because it's hard to do correctly.

Upscaling and downscaling are rather different operations and need separate code paths. If you allow hscale and vscale to differ, you at least double the number of code paths you need (both down, both up, hscale down vscale up, vscale down, hscale up), and perhaps double again, since (in some cases) downscale will already have two paths internally.

Supporting not-very-different hscale and vscale would be pretty easy, which would probably cover most people. I suppose it could print a warning if the scales are either side of unity or if the scales differ by more than 20%.

@bkw
Copy link
Contributor

bkw commented Feb 25, 2015

Thanks for the explaination, @jcupitt !

Unfortunately, for my (admittedly rather odd) usecase this would not be helpful. Maybe other users would still approve, dunno.

@jcupitt
Copy link
Contributor

jcupitt commented Feb 25, 2015

Oh, that's a shame. How large a difference do you need?

@bkw
Copy link
Contributor

bkw commented Feb 25, 2015

The thing is - I don't know! I'm mass-processing images from third party feeds and need to scale them down to a square for further processing. Since i have no control over the source images, the ratio could be anything.

If it helps anything: the target square has a size n*n with n being a power of 2, but never greater than 256:

smallestEdge = Math.min(orig.width, orig.height, 256);
squareSize = Math.pow(2, Math.floor(Math.log(smallestEdge) / Math.log(2)));

@jcupitt
Copy link
Contributor

jcupitt commented Feb 25, 2015

Wow that is a bizarre use case :) I guess this for some sort of query-by-image-content application? If that's the case I suppose you probably wouldn't care about small errors and a simple solution would be fine.

@bkw
Copy link
Contributor

bkw commented Feb 25, 2015

You got that right :-)

I cannot really say how important "small errors" will be before I tried them out, but since the algorithm is resilient against compression artifacts and such things, it will probably be ok.

@lovell
Copy link
Owner

lovell commented Feb 25, 2015

Very happy to accept a PR implementing this feature - there's a fairly basic guide for contributors.

@blowsie
Copy link

blowsie commented Apr 9, 2015

For reference, I always used timthumb in the past, and found the zc (zoom and crop) options very useful and easy to understand.

http://www.binarymoon.co.uk/2011/03/timthumb-proportional-scaling-security-improvements/

This is in some ways related to this ticket
#128 (comment)

@lovell
Copy link
Owner

lovell commented Apr 16, 2015

Thanks to @skedastik this feature will be available in the forthcoming v0.10.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants