josegonzalez/upload — pull request #161 by chmac (2013-09-17 13:10:40+00:00)
Title: Thumbnail enlarge option

I've added a new option `thumbnailEnlarge` which defaults to `true` in keeping with the existing behaviour. If left as `true`, the thumbnail behaviour is unchanged.

If set to `false`, then thumbnails by width, height, or longest side will never be bigger than their original image. So if setting thumbnail sizes like `960l`, `600w`, or `600h` and uploading a small image (400x300), the thumbnail files will be created as normal, but they will be the same size as the original image.

My logic for only modifying the width, height and longest side options is as follows. If I create a thumbnail like `120x120` or `[120x120]`, I know both dimensions of the image, for every thumbnail. But, if I create a thumbnail like `960h`, `960w` or `960l` then I don't know the dimensions of the image. With the first two, I know one dimension, height or width. So if I'm inserting the thumbnails somewhere into an `` tag, I need to somehow work out the dimensions to add a `width` and `height` attribute.

For that reason, I think it makes sense to always enlarge the original image if the exact thumbnail sizes are specified. But, give users the option not to enlarge the height, width or longest side thumbnails.

The use case for this feature in our http://composer.io/ application is as follows. Users can upload images which are destined for different places. Some go to Facebook, some Twitter, some WordPress, and some are hosted by the application itself. Facebook only accepts images up to 960px x 960px. So we're using the thumbnail functionality to create a version `960l` for facebook. Then we're creating a `600l` version to host ourselves. But if a user uploads a small image, we don't want to enlarge it to 960px wide, and then send it to Facebook. In that scenario, we just want to send the original image if it's less than 960px. Likewise for hosting it ourselves.

Hopefully all of this makes sense. I've tested the three options, and without explicitly setting `thumbnailEnlarge` to true, the plugin works as normal. I think this option could be useful to users, so here's the pull request... :-)