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

Resizing images using a for loop #20

Open
bilal-karim opened this issue May 7, 2017 · 0 comments
Open

Resizing images using a for loop #20

bilal-karim opened this issue May 7, 2017 · 0 comments

Comments

@bilal-karim
Copy link

I’m trying to resize images all of the images inside a directory using a for loop, but having some troubles.

{% for image in images %}
    <img src="{{ url_for('static', filename='img/photos/' + image|resize('600x400', quality=100)) }}">
{% endfor %}

Results in the following error:

flask_resize.exc.UnsupportedImageFormatError
UnsupportedImageFormatError: JPEG and PNG are the only supported output file formats at the moment.

All images inside the directory are JPEGs, and they have ".jpg" as their extension so I’m not sure why I’m getting that error. Flask-Resize itself is working fine, as I tested it on one single image by hardcoding the path to the file. But I need all of the images on this page to resize.

I also tried this inside my for loop:

{% set myURL = 'img/photos/' + image %}
<img class="slb" src="{{ myURL|resize('600x400', quality=100) }}">

This is my code on the back-end:

@app.route("/photos")
def photos():
    images = os.listdir(os.path.join(app.static_folder, 'img/photos'))
    return render_template("photos.html", images=images)
@bilal-karim bilal-karim changed the title Resizing images in a for loop Resizing images using a for loop May 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant