sorl-thumbnail | Thumbnails for Django
kandi X-RAY | sorl-thumbnail Summary
kandi X-RAY | sorl-thumbnail Summary
Thumbnails for Django
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Get a thumbnail for a file
- Set the image size
- Flips image dimensions
- Creates alternative resolution
- Crops the image
- Crop the image
- Handles actions
- Delete all thumbnails
- Write an image
- Read the contents of the file
- Return the raw value stored in the cache
- Set raw value for key
- Remove all keys from the cache
- Check if the given image is portrait
- Get image data
- Pad image
- Clear all keys from THUMBNAIL_KEY
- Creates an image
- Removes the border of the image
- Render the node
- Set the orientation of the image
- Get raw data
- Delete a file reference
- Calculate the background margin
- Write image
- Return the ratio of the image
sorl-thumbnail Key Features
sorl-thumbnail Examples and Code Snippets
from subject_imagefield.fields import SubjectImageField
class MyModel(models.Model):
image = SubjectImageField('image', upload_to='pages/img', subject_location_field='subject_location')
subject_location = models.CharField('subject coords', m
def save(self, *args, **kwargs):
preview = get_thumbnail(self.photo, '250x250', crop='center', quality=99)
self.preview.save(preview.name, ContentFile(preview.read()), save=False)
super(sitePhotos, self).save(*args, **kwargs)
<
ratio=x/y
req_width=int(height*ratio)
if(req_width
def ImgDim(width,height,ratio):
#ratio is width:height
if 'x' in ratio:
return ratio
x,y=ratio.split(":")
x,y=int(x),int(y)
ratio=x/y
req_width=int(heigh
pip install virtualenv
cd my_project_folder
virtualenv my_project
certifi==2018.10.15
chardet==3.0.4
Click==7.0
cycler==0.10.0
decorator==4.3.0
Flask==1.0.2
gunicorn==19.9.0
idna==2.7
ipython-genutils==0.2.0
itsdan
sudo apt-get install libjpeg62 libjpeg62-dev zlib1g-dev
pip install Pillow
Community Discussions
Trending Discussions on sorl-thumbnail
QUESTION
We have deployed a django server (nginx/gunicorn/django) but to scale the server there are multiple instances of same django application running.
Here is the diagram (architecture):
Each blue rectangle is a Virtual Machine.
HAProxy sends all request to example.com/admin to Server 3.other requests are divided between Server 1 and Server 2.(load balance).
Old Problem:
Each machine has a media folder and when admin Uploads something the uploaded media is only on Server 3. (normal users can't upload anything)
We solved this by sending all requests to example.com/media/* to Server 3 and nginx from Server3 serves all static files and media.
Problem right now
We are also using sorl-thumbnail.
When a requests comes for example.com/,sorl-thumbnail tries to access the media file but it doesn't exist on this machine because it's on Server3.
So now all requests to that machine(server 1 or 2) get 404 for that media file.
One solution that comes to mind is to make a shared partition between all 3 machines and use it as media. Another solution is to sync all media folders after each upload but this solution has problem and that is we have almost 2000 requests per second and sometimes sync might not be fast enough and sorl-thumbnail creates the database record of empty file and 404 happens.
Thanks in advance and sorry for long question.
...ANSWER
Answered 2021-Dec-26 at 19:53You should use an object store to save and serve your user uploaded files. django-storages makes the implementation really simple.
If you don’t want to use cloud based AWS S3 or equivalent, you can host your own on-prem S3 compatible object store with minio.
On your current setup I don’t see any easy way to fix where the number of vm s are dynamic depending on load.
If you have deployment automation then maybe try out rsync so that the vm takes care of syncing files with other vms.
QUESTION
I'm using Python 3.6.9, Django 3.2.8, sorl-thumbnail 12.7.0 with memcached and apache2
my thumbnails completely disappear and give a 404 when settings.py variable DEBUG is set to False.
I also have to say, that I don't get any errors displayed at all from setting THUMBNAIL_DEBUG = True as I understand it depends on the aforementioned variable which I have to set to False for pictures to disappear, if it does not depend on it I'm not getting any error displayed either.
I'm just loading them inside templates like this:
...ANSWER
Answered 2021-Nov-29 at 11:23The problem was in my apache2 site configuration file that wasn't serving the /media Alias as the directory path had changed.
Refer to this page of the documentation in case.
QUESTION
I'm having a bit of a difficult time with performance using sorl-thumbnail. I'm hosting images on S3 with the S3Boto3Storage storage backend, I'm using Redis as my Key-Value Store and all queries have been cached inside it already. I'm using the following dependencies:
...ANSWER
Answered 2021-Aug-01 at 17:58Okay, figured out what was wrong. I had set AWS_S3_CUSTOM_DOMAIN
in settings, but had accidentally overwritten it in my storage class:
QUESTION
I'm trying to get my head around how sorl-thumbnail works but getting a bit confused.
I know it get's a key depending on the image and its settings then saves/returns the value when it's needed. To me this seems like it would all be done with the cache. I just don't get why it's saving the key/value in a database too.
Can you explain why you need a cache engine and also a database? It doesn't make sense to me why it would need to use both.
...ANSWER
Answered 2021-Mar-25 at 20:45Caches (in Django and in general) are generally faster to read and write but don't necessarily guarantee durability of the data stored.
Using the database as slower but durable storage and the cache as faster storage in front is a pretty normal pattern -- heck, Django even has a session storage backend django.contrib.sessions.backends.cached_db
that does just that.
QUESTION
So I have a model like this
...ANSWER
Answered 2021-Feb-02 at 02:26as far as I know this is why the first exception arises.
QUESTION
So I am using fallback default image to avoid 500 error and it is not successful. I keep getting the same error "InvalidImageFormatError: The source file does not appear to be an image".
In my case I try to thumbnail an image that does not exist.
But it is assumed that if the image does not exist it should use the one that is in default as fallback.
Any ideas? Someone who has happened in the same way and found a solution?
In my case this is my code {% oscar_thumbnail child_image.original|default:'image/default.png' "450x450" format="WEBP" padding=True as thumb_child %}
I am migrating from sorl-thumbnails which comes by default with django_oscar for easy_thumbnails. The tag OSCAR_THUMBNAIL is used by django_oscar and oscar replaces it with the thumbnailer that is in settings in this case easy_thumbnails. I have debugged the code, and it is entering the easy_thumb classes well ... and the parameters are arriving correctly. The thing is, it doesn't make me fallback when the image it's trying to process doesn't exist. I have a database with products that have associated images, many of these do not exist in my local environment, because in production they are in s3, and I do not have my settings configured for s3 in my development environment. But hey, the question is that it should fallback when there is no image, or there is a reference to an image that does not physically exist. With which I intend to do fallback if it exists but it keeps giving me error 500 and it does not show me the page, I get the django page with the exceptions. Oh and I've also tried the native easy_thumb tag ...
Any ideas? Thanks in advance!
...ANSWER
Answered 2020-Nov-24 at 14:59The problem was the following, for the default filter to take the value the previous expression must be evaluated to False, for this reason it explodes, because there is no image, the thumbnailer cannot create the object, the solution is to make another filter to check if the image exists in the storage, and return a boolean value.
QUESTION
I am trying to have a form to generate thumbnails from images that will be uploaded
I will be using sorl for the thumb generation and I am following the following documentation:
- Django multiple file upload: https://docs.djangoproject.com/en/3.0/topics/http/file-uploads/
- Sorl Low level API: https://sorl-thumbnail.readthedocs.io/en/latest/examples.html
When I try to generate the thumbnail I get the error of
...ANSWER
Answered 2020-Jul-16 at 08:27As you have said in the question, you do not want to store in root and generate thumbnail. Then I would suggest something like this:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sorl-thumbnail
You can use sorl-thumbnail like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page