mikeboers / Flask-Images

On-demand resizing of images for Flask applications.
https://mikeboers.github.io/Flask-Images/
BSD 3-Clause "New" or "Revised" License
81 stars 43 forks source link

Crop Resize #28

Closed jamesharding closed 9 years ago

jamesharding commented 9 years ago

More of a feature request than an issue:

If an uploaded image is 200x400px, and in crop mode the desired output is 400px by 400px, would it be possible to allow the outputted image to be a zoomed/enlarged cropped image that is 400x400px and zoomed on the centre of the image? Right now, the output will never be larger than the original (and would output an image of the original 200x400 size in the above example).

mikeboers commented 9 years ago

I faced the same issue recently on my own photo site during the transition to HiDPI images. As of v2.1.0, cropped images should be enlarged unless you pass enlarge=False (see example from my site).

Let me know if the latest version is[n't] working for you.

jamesharding commented 9 years ago

On your site, that is in fit mode as opposed to the crop mode. With fit, the aspect ratio of the original image is unchanged, but I guess that what I am looking for is for image to be scaled up to have its shortest edges > the required size, and then for the crop to happen. In my case I want all outputs to be perfect squares), and for them to all be the exact size that is passed to the function.

I am using resized_img_src(user.photo_path, width=400, height=400, mode='fit', quality=95) as my call. If the pictures have both edges longer than 400px it works perfectly. If one edge is less than 400px, then the output image no longer has a square aspect ratio.

mikeboers commented 9 years ago

There is also this example, in which I am enlarging a crop because I too want perfect squares (or rectangles; here it is in action).

I could be wrong and mine working due to the HiDPI-ness. Can you confirm for me you are on v2.1.0, or the master from GitHub?

jamesharding commented 9 years ago

I am on the PIP version 2.1.1. With the version on your site, if you passed it an image that was smaller than the desired output, does is still correctly scale it up and maintain the output size/aspect ratio?

screenshot 2015-01-07 21 28 15

screenshot 2015-01-07 21 30 52

Here is what it looks like, with Tom's picture being 265x331 input, and the output is also 265x331.

mikeboers commented 9 years ago

I think it is actually an issue with caching. Stay tuned.

mikeboers commented 9 years ago

I think it was a caching issue (in which the enlarge parameter wasn't being taken into account when caching the results, so if you added enlarge=True without changing anything else then it wouldn't even try to resize the image).

Please try the new master. I've also tried to document a few more parameters. ;)

jamesharding commented 9 years ago

Hmmm, it still seems to be an issue even with the latest master. Have you tried testing it on your site with an image that is smaller than the output resolution (and not of the same aspect ratio too)?

mikeboers commented 9 years ago

Yup. The demo works as expected too (the source is 240x160).

jamesharding commented 9 years ago

Brilliant, that has fixed it :) I needed to restart my gunicorn instance for it to load the new flask-images version.

Thank-you! This plugin is fantastic.

mikeboers commented 9 years ago

Awesome! You should see the problems I have when I keep introducing this same caching bug over and over...

I'll let it settle, and then release on the PyPI.

mikeboers commented 9 years ago

I have now released this on the PyPI as v2.1.2. =]