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

How to use Flask_Images? #30

Closed kramer65 closed 9 years ago

kramer65 commented 9 years ago

This may be a weird issue, but I'm kind of confused how to use this plugin. I loaded it by doing this:

from flask_images import Images
Images(app)

I then tried transforming this (withinin a template):

<img src="{{ url_for('static', filename='have-a-nice-day.jpg') }}">

into this:

<img src="{{ resized_img_src('static', filename='have-a-nice-day.jpg', width=50) }}">

but that results in the following url, which doesn't return anything

<img src="/imgsizer/static?filename=have-a-nice-day.jpg&amp;w=50&amp;s=Fw0kPelkfO6usnzyiGGZ87aYmws">

I tried some other variations, such as the ones below. But I can't get it to work:

<img src="{{ url_for('static', filename='have-a-nice-day.jpg', width=50) }}">
<img src="{{ url_for('static.crop', filename='have-a-nice-day.jpg', width=50) }}">

Could anybody help me out in how I should get this to work? All tips are welcome!

mikeboers commented 9 years ago

Please try either:

<img src="{{ resized_img_src('have-a-nice-day.jpg', width=50) }}">

or

<img src="{{ url_for('images', filename='have-a-nice-day.jpg', width=50) }}">
kramer65 commented 9 years ago

@mikeboers - Thank you for your suggestions. Unfortunately neither works for me. Both of them return the following html:

<img src="/imgsizer/have-a-nice-day.jpg?v=VQSPQQ&amp;w=50&amp;s=VuB4ukXnLlvDwsGFYTyjExrTEKI">

which results in this:

Broken image

I don't know if Flask_Images should automatically build the /imgsizer url, but it simply doesn't seem to exist. I'm not sure what else I can try now.

Seeing this situation, would you have another tip to get this to work?

kramer65 commented 9 years ago

Turns out that I didn't have libjpeg-dev installed on my Ubuntu server. This solved it:

sudo pip uninstall PIL
sudo apt-get install libjpeg-dev
pip install -I pillow

Thanks for creating flask-images!