GithubHelp home page GithubHelp logo

jacobsvante / flask-resize Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 11.0 159 KB

Flask extension for resizing, cropping and caching images.

Home Page: https://flask-resize.readthedocs.io/

License: Other

Python 99.02% Shell 0.98%
python flask resize-images aws-s3 redis

flask-resize's People

Contributors

jacobsvante avatar waffle-with-pears avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

flask-resize's Issues

Please explain

Hi @jmagnusson i am a developer who want to use your resize ext but i have question that i cannot ask you direct so i made an issue, sorry about that.
As you said, when i use your ext, i must config

Where your media resides

RESIZE_ROOT = '/path/to/your/media/root/'

The URL where your media is served at. For the best performance you

should serve your media with a proper web server, under a subdomain

and with cookies turned off.

RESIZE_URL = 'http://media.yoursite.com/'
In my cake i set:
RESIZE_ROOT = '/tmp/instance/uploads/'
RESIZE_URL = 'http://localhost/media'
So i got image url is http://localhost/media/cache/hash_value.ext'
The question is i must implement function to serve this request right?? And have any way to serve it automatically in ext???
Thank you very much!!

Blank image, no errors

I was pretty sure I configured this correctly, but it did not work for me. Here's how I've set it up in my local development environment on Windows:

In __init__.py:

import flask_resize
app.config["RESIZE_URL"] = 'http://local.dev:5000/'
app.config["RESIZE_ROOT"] = 'app/static/img/'
app.config["RESIZE_CACHE"] = 'app/static/cache/'
flask_resize.Resize(app)

Then in my HTML page:

<img src="{{ 'main/my-image.png'|resize('600x400') }}" alt="Title"/>

It does not return any image. The URL that gets generated is as follows:
http://local.dev:5000/cache/865060049cfbff6bf8e1f9b9da74a7d9.png

Any guidance or help would be appreciated. Cheers.

'Fill' fit image instead of cropping

Coming from 0.2.2 version (really :D ). The 'fill' argument is acting like "resize to fit", not " resize to fill". Docs says "With fill it will crop the image", but instead it just fill with white color.
Here is an example.

0.2.2

7fb59b3b385593414de2d41c1e7c2383 1

2.0.2

394d230a7b2811ebc7de3a935913cdc22f5d5998

Incorrect cache file path on Windows

When running Flask-Resize under windows, the generated cache path is invalid as it uses the OS libraries to generate the file path.

Eg when using RESIZE_URL='http://127.0.0.1:5000' and RESIZE_ROOT='./static/images/' results in the cache path http://127.0.0.1:5000\static/images/cache/<hashed filename>

The backslah after the RESIZE_URL is invalid as a web address.

Update / Clear cache

If I replace an image by another one I will still see the same old image if I use resize option. I figured out the only way to get the new image is to delete the cache directory so that all images get rebuilt. Would be great to have a function clear_cache or even being able to rebuild the cache.

Handling Redis authentication

Hi

I see that there is a key option, but unless I'm mistaken, this is not for providing a password.
Is there a way for me to do so? Presently I've disabled authentication, but I would like to re-enable it before running my production server.

Whilst I'm here, would just like to say thank you for creating Flask-Resize, it's very nice ๐Ÿ‘.

Is the bgcolor attribute broken?

I am trying resize(file.path, str(width) + 'x' + str(height), fill=1, quality=40, format='jpeg', bgcolor='#40464e')
I get the error.
File "D:\MegaSync\Languages\Python\CT83-PC\venv\SmartCow-Image-Gallery\lib\site-packages\flask_resize\resizing.py", line 303, in generate data = self._generate_impl() File "D:\MegaSync\Languages\Python\CT83-PC\venv\SmartCow-Image-Gallery\lib\site-packages\flask_resize\resizing.py", line 260, in _generate_impl mat_color = ImageColor.getrgb(self.bgcolor) File "D:\MegaSync\Languages\Python\CT83-PC\venv\SmartCow-Image-Gallery\lib\site-packages\PIL\ImageColor.py", line 127, in getrgb raise ValueError("unknown color specifier: %r" % color) ValueError: unknown color specifier: '40464e'

Resizing images using a for loop

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)

Add webp support

it would be great to add support for image generation in webp format

Ability to add custom storage

It would be great to have ability to add our own custom storage.

In my case I would like to use MongoDb`s GridFS.

However at this time I could not implemented it due restrictions in make function in storage.py

Getting error when running pip or setup.py

Would like to try the library but am getting the following error related to the fix for :tweepy/tweepy#533.

Traceback (most recent call last):
File "setup.py", line 28, in
requirements = parse_requirements('requirements.txt', session=uuid.uuid1())
TypeError: parse_requirements() got an unexpected keyword argument 'session'

Sugestion: Return orriginal image if resize is same size

I noticed that when using a resize size that was the same size as the original file or when specifying a larger size with upscale=False, that a hashed cache file was still created.

I haven't delved into the code enough so I don't know if the cached file is a direct copy but even if it is, at best Flask-Resize is creating excess duplicate files, which could be a problem on a large image cdn and, at worst, is performing excess processing as well to produce the same image, which results in extra cpu usage and possibly a loss in quality.

I would recommend, if no other transformations of the image need to be performed and the requested size is the same as the original size, then Flask-Resize should serve the original image. perhaps add another possible parameter and call it force_cache or similar, and default it to False; setting the parameter to True will then force Flask-Resize to produce a cached image, even if size is the same as the original.

use url to detect extension

Hello,

I try to use for images an url without an extension (jpg,png...), e.g.
http://127.0.0.1:5000/picture/123456789abc
This is necessary since I use an id in the url and the algorithm searches in the background an corresponding image.

For example, if I use

this works fine. The url which was created
http://127.0.0.1:5000/picture/123456789abc
sends the content type image/jpeg and shows the image in the browser.

If I add the resize command

I've got the exception "Only JPG or PNG are allowed...."

If I debug Flask Resize, I see that flask modules uses the url to detect the extension and not the content type of the send content. For me it looks like an issue. Maybe an alternative fix exists?

Thanks
Tobias

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.