jacobsvante / flask-resize Goto Github PK
View Code? Open in Web Editor NEWFlask extension for resizing, cropping and caching images.
Home Page: https://flask-resize.readthedocs.io/
License: Other
Flask extension for resizing, cropping and caching images.
Home Page: https://flask-resize.readthedocs.io/
License: Other
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
RESIZE_ROOT = '/path/to/your/media/root/'
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!!
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.
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.
I am having trouble with Flask-Resize. Image is resized but it is just grey. I got only filename on grey background.
Take a look.
http://imgur.com/dPJJAn9
My img_path is ok. When I do src="{{ img_path }}" image is shown. Bu on "{{ img_path|resize('80x80') }}" it is just grey.
For me the issue persist - the image is rendered with the image url
like as text: http://images3.uread.com/productimages/mainimages/682/9788131708682.jpg
http://imgur.com/zK6EWnT (the image contains the URL)
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.
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 ๐.
Sometimes the error message will not be readable because the text isn't adjusted to the available space. An example taken from issue #5:
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'
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)
it would be great to add support for image generation in webp format
When generated as JPEGs.
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
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'
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.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.