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

Ignoring aspect ratio in vipsthumbnail #648

Closed
kleisauke opened this issue Apr 27, 2017 · 8 comments
Closed

Ignoring aspect ratio in vipsthumbnail #648

kleisauke opened this issue Apr 27, 2017 · 8 comments

Comments

@kleisauke
Copy link
Member

Sometimes it's needed to ignore the aspect ratio and distort the image so it always generates an image exactly the size specified. With imagemagick this can be done with ! flag, see:

convert terminal.gif -resize 64x64\! exact_terminal.gif

(terminal.gif can be downloaded here)

There's not yet an option to do this with vipsthumbnail.

Background information
The resize logic from our image cache and resize proxy (which uses libvips as back-end) has much in common with the vipsthumbnail operator. Unfortunately, we can't use the vipsthumbnail operator (yet) because it doesn't support ignoring the aspect ratio (which we've supported for almost 7 years now).

In order to not break anyone's apps, we'll like to see that this feature is incorporated in the vipsthumbnail operator.

How much demand is there for this feature?
I don't know the exact numbers of developers who'll like to see this feature in vipsthumbnail, but I think there is still some demand for it. See:
lovell/sharp#118
http://stackoverflow.com/questions/42708357/resizing-stretching-with-vipsthumbnail/

To see how much demand there is for this feature, please vote with a 👍 reaction.

Number of requests
For a week, we've monitored the usage of a parameter (&t=absolute) to ignore the aspect ratio. A total of 7,875 uncached requests were made on 2,633 unique images (which can be seen as a small number of requests).

Use case scenarios
We found out that there are some specific use case scenarios where ignoring the aspect ratio will come in handy:

  • A single-color image to use as background for different types of devices.
  • Placeholder images like X (or to overlay over another image).
  • Converting ellipses to circles and vice versa (see this for example, not sure why people do this 😕).

Relevant links (for implementation)
lovell/sharp#192

@jcupitt
Copy link
Member

jcupitt commented Apr 30, 2017

For implementation, perhaps the simplest way to add this is to add a new value for VipsSize:

http://jcupitt.github.io/libvips/API/current/libvips-resample.html#VipsSize

That's the thing that's set by < and > at the end of a 100x200 or whatever size specification.

We could add a new value, perhaps FORCE, which forces the image to exactly those dimensions, ie. breaks aspect. It sounds like vipsthumbnail.c should use ! at the end of a size specification to trigger this.

@jcupitt
Copy link
Member

jcupitt commented May 4, 2017

OK, it seems to work. Just needs some tests.

$ vipsthumbnail k2.jpg -s 100x5\!
$ vipsheader tn_k2.jpg 
tn_k2.jpg: 100x5 uchar, 3 bands, srgb, jpegload

You can't mix < > and !, it has to be just one of those modifiers, but hopefully that's OK.

@kleisauke
Copy link
Member Author

Just tested it, and it works! Awesome! 👍

I don't think there is a use case to mix those modifiers, so just one modifier is OK.

Found only 1 bug in combination with auto_rotate. It doesn't seem to force the dimensions when there is EXIF orientation. You can try this image in combination with auto_rotate and VIPS_SIZE_FORCE.

@jcupitt
Copy link
Member

jcupitt commented May 5, 2017

OK, autorot seems to work. I'll add some more tests.

@jcupitt
Copy link
Member

jcupitt commented May 5, 2017

Added some tests, it all seems to work. I'll leave it a day two for more testing, then merge to master.

Thanks for pushing for this, @kleisauke.

@jcupitt
Copy link
Member

jcupitt commented May 10, 2017

Merged to master! I'll close. Thanks for testing!

@jcupitt jcupitt closed this as completed May 10, 2017
@kleisauke
Copy link
Member Author

Thanks for incorporating this in vipsthumbnail!

I think libvips have a time-based release cycle of 6 months (just like Ubuntu). So I guess 8.6.0 will be released in October 2017?

@jcupitt
Copy link
Member

jcupitt commented May 10, 2017

Yes, it's a while off, probably.

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

2 participants