Ways to handle thumbnails with Django? - django

I'm going to have different ways to present an objects image in my templates. Full size, medium size and smaller thumbnails in lists. It's a dynamic structure and needs to be fast for sorting, searching, filtering..
As a beginner I'm thinking of three ways to handle this:
Simply use the image from the image field and change the size in templates with css.
Save different image versions (size) in different fields in the model and in media files.
Create the thumbnails dynamically in the templates with sorl-thumbnail or easy-thumbnails
The thumbnail apps is a bit complicated and would need some extra requirements like PIL and I need to make some choices about caching. Not sure if I win so much performance by going down this path or if there is other smarter ways? Is it better to plan ahead for scaling/performance.
How are you handling thumbnails? And are you using redis or memcached?

First neither redis or memcached handles caching of images. Memcached is a simple key-value store. Redis essentially works as a key-value store but it has support for other types as well. Such as lists. When it comes to caching images you would use something like nginx.
Secondly, the first option is suboptimal if you want your page to load as quickly as possible. As it will need to load a bigger file than necessary. The second and the third option is essentially the same. Easy-thumbnails for example doesn't create thumbnails on the fly in the template. It generates them as needed and then you can access those thumbnails from your static_folder.
If you want to manipulate images, you will need PIL or Pillow if you're using Python 3.

Related

image metadata, Can I add custom fields or comments?

I am a bit lost on what to do here. I have a django app that will be using a lot of images and I want to keep track of the source of all these images.
I had it setup to have a model that has two fields (FilePath and Char) that I would use to store the image path and the source, but now I am thinking that is a waste of energy. I would like to store the source right with the image.
What would be the best way to go about this?
(possibility) I see in my OSX finder that there is something called comments, can these be accessed across all machines or is this OSX specific?
The answer turned out to be definitely no. I will have to be adding another model field to store this information

CKFinder: How to create small, medium, and large images automatically from image upload

I am looking for a way to make small, medium, and large copies of an image automatically when uploaded through CKFinder 2.5. Basically I want the same image copied and resized to different sizes so that I can use different images for my responsive site. The imageresize plugin does similar, but not quite what I am looking for since it is still initiated by the user.
I would prefer to add the code to the config file over adjusting code in the core folder. I am using coldfusion, but I would appreciate ideas in any language possible so I can make something work. Thanks in advance!

Using sorl-thumbnail with MongoDB storage

I've extended sorl-thumbnail's KVStoreBase class, and made a key-value backend that uses a single MongoDB collection.
This was done in order to avoid installing a discrete key-value store (e.g. Redis).
Should I clear the collection every once in a while?
What are the downsides?
Only clear the collection if low disk usage is more important to you than fast access times.
The downsides are that your users will all hit un-cached thumbs simultaneously (And simultaneously begin recomputing them).
Just run python manage.py thumbnail cleanup
This cleans up the Key Value Store from stale cache. It removes references to images that do not exist and thumbnail references and their actual files for images that do not exist. It removes thumbnails for unknown images.

django image management

In my project I'am working with images. I don't know how to organize the management of images.
I need to dynamically upload the pictures and resize them.
First question - what is the best way to dynamically upload images with progress bar and without flash? I found this and this, but I believe there is a better way.
Second question. I have to save one image in different sizes. I won't use these thumbnails on my pages, but another application will. Many clients could upload images at the same time. This means that I can not resize all the images at the same time. How should I organize this process?
Is there are a better ready-to-use solution for image management issue?
django-photologue could be a good starting point for organizing the management of your images.
The PhotoSize model can be used to automatically resize/crop your images, and the GalleryUpload model allows the user to upload an archive of images.
You can also create PhotoSize models with pre_cache = False. This means that your images will dynamically created the first time they are requested.
For your second question you might use a task queue, like django-celery or django-tasks.
For the image crop, try Python Imaging Library (PIL)

User-Defined Thumnails for Django Project?

I'm putting together a Web site that makes heavy use of images. Those images need to be thumbnailed at various sizes to fit different templates.
I'm aware of solutions like sorl-thumbnail, which seems perfect in every way except one: I need to be able to override automatic resizing and cropping if the computer's choice is a bad one.
For instance: Say I upload a 1,000-by-1,000 pixel image. I need a 300-by-200 thumbnail of that image. The sorl-thumbnail solution, if I understand it right, is to rescale the image to 300-by-300 and then lop off the top and the bottom.
What I want to be able to do is a) accept the sorl-style solution if it works for the image, but b) be able to override the sorl choice -- in the admin, probably -- if that would work better. If it's a picture of a person, for example, maybe I would rather crop out the person's torso and just make a thumbnail out of her face, which happens to be located in the upper right corner?
There's no off-the-shelf pluggable solution for this, so far as I can tell (but please correct me if I'm wrong). Barring that, I'd like to hear your ideas about ways that the problem might be approached. Is there some sort of jQuery plugin that will get me halfway there?
Help!
If you want to use an off-the-shelf pluggable there is django-photologue django-imagehandler. It allows you to generate thumbnails and do "manual-cropping" on the admin.
Another off-the-shelf solution is django-thumbs. django-thumbs overwrittes your imagefields. The only drawback is that you need to set up the sizes it will generate the thumbnails.
None of these 2 applications can fully solve your problem. But atleast you know where to start :)
django-photologue can generate thumbnails and add effects and watermarks.
EDIT: if you want to use jQuery to crop your images then you can take a look at jCrop. It's pretty easy to use. The main problem is that you will need to upload the image to your server and then crop it manually.
EDIT 2:Wrong information. It was not django-photologue but django-imagehandler.
sorl-thumbnail has smart cropping which will cut off the parts of the image with the least entropy. All you need to do is add crop="smart". It works really really well in most situations.
Otherwise you could check out django-imagehandler