silentsokolov / flask-thumbnails Goto Github PK
View Code? Open in Web Editor NEWA simple extension to create a thumbs for the flask framework
License: MIT License
A simple extension to create a thumbs for the flask framework
License: MIT License
If I try to set an alternate folder via
app.config['MEDIA_THUMBNAIL_FOLDER']
app.config['MEDIA_THUMBNAIL_URL']
I see that it allways try to write to the original folder.
The problem is that in init.py/class Thumbnail/thumb_url = os.path.join(self.app.config['MEDIA_THUMBNAIL_URL'], url_path, miniature)
url_path starts_with trailing '/' and this leads to:
thumb_filename='%s/%s' % (url_path,minitature)
-> same for thumb_url
You can see what happens if you use
os.path.join('/a','/b','/c') vs
os.path.join('/a','b/b','/c')
This is just a quick note, to let you know that I've created a fork of flask-thumbnails called 'flask-thumbnails-s3', which is up here:
https://github.com/Jaza/flask-thumbnails-s3
It works pretty much the same as flask-thumbnails when set to use the local filesystem, but it can also be set to load / save thumbnails to an Amazon S3 bucket.
Thanks to silentsokolov and the other contributors of flask-thumbnails, for the code that I've re-used in flask-thumbnails-s3, and thanks for the generous MIT license - I believe I've followed the terms of the license (and the spirit of open source in general), but let me know if you have any issue with this fork.
If anyone else needs flask thumbnails working via S3, hope this new project is of use to you.
(And feel free to close this issue whenever you want).
If you try to thumbnail a PNG (with alpha channel) you get an Pillow error:
File ".../python3.6/site-packages/PIL/JpegImagePlugin.py", line 604, in _save
raise IOError("cannot write mode %s as JPEG" % im.mode)
OSError: cannot write mode RGBA as JPEG
title
In our use case we're sometimes uploading images directly from smartphones directly after taking. Some of the images are rotated in odd ways when served via flask-thumbnails. It seems to have to do with the EXIF tag "Orientation", which gives a hint to how the camera was held.
More details and how to cope with the problem are discussed here: https://stackoverflow.com/questions/4228530/pil-thumbnail-is-rotating-my-image
I love your plugin, but I'm looking for a way to have the file name be variable. Something like this, though it doesn't work:
<img src="{{ {{image_name}} |thumbnail('200x200') }}" alt="" />
Thanks!
See line 32 of flask-thumbnails/flask_thumbnails/storage_backends.py.
The 'exist_ok' argument is Python 3 only.
Currently, flask_thumbnails requires Pillow 2.2.1. This old version of Pillow has an installation bug.
Can the required version number be removed, or at least updated to 2.6.0? As far as I can tell, this version of Pillow works fine for flask_thumbnails.
In Option settings said, as i understand, i can set THUMBNAIL_MEDIA_THUMBNAIL_ROOT and thumbs will be saved there.
So i set:
ROOT_PATH = os.path.join('/home/devadmin','.cdnstatic')
THUMBNAIL_MEDIA_ROOT = ROOT_PATH
THUMBNAIL_MEDIA_THUMBNAIL_ROOT = os.path.join(ROOT_PATH,'.thumbnails')
So, paths will be:
/home/devadmin/.cdnstatic
/home/devadmin/.cdnstatic/.thumbnails
My originals saved in other path:
/home/devadmin/.cdnstatic/digital_image/1023/68/1-first.jpeg
Next, function calculated parameters:
original_filepath = os.path.join(self.root_directory, original_path, original_filename)
That is correct: /home/devadmin/.cdnstatic/digital_image/1023/68/1-first.jpeg
But:
thumbnail_filepath = os.path.join(self.thumbnail_directory, original_path, thumbnail_filename)
calculated as: /home/devadmin/.cdnstatic/digital_image/1023/68/<thumbnail_filename>
So my thumbs saved in same directory as originals. I try to swap <self.thumbnail_directory> and <original_path> (i think need to remove <original_path>), then it calculated as i expected: /home/devadmin/.cdnstatic/.thumbnails/<thumbnail_filename>
Same for thumbnail_url function
Can you fix this, or am I wrong and am doing something wrong?
Why do you prompt for the user to manually install you package dependencies instead of putting them in your setup.py so that they aree automatically installed with your package ?
I'm unsure how to use the thumbnails.
<img src="{{ image|thumbnail('200x200') }}" />
Is not working.
How I got it working is:
<img src="{{ url_for('uploaded_file_thumb', filename=image, size='200x200') }}" />
And the app.py:
app = Flask(__name__)
thumb = Thumbnail(app)
...
@app.route('/thumb/<filename>/<size>')
def uploaded_file_thumb(filename, size):
t = thumb.thumbnail(filename, size)
return send_from_directory(app.config['UPLOAD_FOLDER'], t)
Hey there,
I'm trying to install your extension via:
pip install git+https://github.com/SilentSokolov/flask-thumbnails.git
But I keep getting the error:
p11-kit: couldn't load module: /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so: /usr/lib/x86_64-linux-gnu/pkcs11/gnome-keyring-pkcs11.so: cannot open shared object file: No such file or directory
I'm using Ubuntu x64. I've tried to install the p11-kit and it installs, but I still can't install flask-thumbnails.
Any ideas what I should do?
Many thanks
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.