matthewwithanm / pilkit

Utilities and processors built for, and on top of PIL
BSD 3-Clause "New" or "Revised" License
196 stars 54 forks source link

Proportional thumbnail #15

Closed brianjbuck closed 9 years ago

brianjbuck commented 9 years ago

This change provides a way for an image to be scaled proportionally. I may not know if the provided image is portrait or if it is landscape, but I do know that I want to make the largest dimension a certain size without cropping the image.

matthewwithanm commented 9 years ago

Hey, @brianjbuck! Thanks for the PR, but how is this different than just passing the same dimension for the width and height? For example, Thumbnail(400, 400).

brianjbuck commented 9 years ago

Your example creates a square even if the input is a rectangle. I don't want a square. I want to keep a rectangle but I don't know in advance if that rectangle is (400, 200) or (200, 400). This way I can just get back a thumbnail resized by the largest dimension and not worry if that dimension is the width or the height.

matthewwithanm commented 9 years ago

Oh, sorry. Like Thumbnail(400, 400, crop=False)?

brianjbuck commented 9 years ago

Ah, I see. It was unclear from the documentation what crop=False would do. In that case I suppose we can close the PR. Thanks @matthewwithanm !

matthewwithanm commented 9 years ago

No problem. The docs could definitely be improved and I'd be super grateful for a PR for that.

The Thumbnail processor is actually a bit special…it's meant as a kind of "higher order" processor, that just composes a bunch of the other ones in a way that would generally be useful for thumbnails. In your case though, you could probably just use ResizeToFit directly. It works like CSS's "background-size: contain"—no cropping.

brianjbuck commented 9 years ago

I might look at clarifying some of the docs. Thanks!

matthewwithanm commented 9 years ago

:thumbsup: Thank you!