Login

Tag "thumbnails"

Snippet List

Image model with thumbnail

A relatively simple Photo model which generates its own thumbnail when saved. A default size is specified as `thumb_size` in the `save()` arguments. Other thumbnailing strategies don't save the thumbnail dimensions, and since the actual dimensions of the thumbnail created by PIL's `thumbnail` method are somewhat non-deterministic, it is difficult to create an `img` tag with proper height and width attributes. This approach makes that task simple. This approach works well if only one thumbnail size is required. It could easily be adapted to support two or three thumbnail sizes, but adding more sizes would quickly get unwieldy. This was adapted from http://biohackers.net/wiki/Django1.0/Thumbnail

  • image
  • thumbnails
  • thumbs
Read More

Unsharp Mask with PIL and PythonMagick

**A Magick PIL** I used to do my image conversions with ImageMagick and system calls back in my PHP days. With Django PIL is the obvious choice for most image stuff, but frustrated by the lack of a proper unsharp mask function for PIL I found some code in the bits and pieces of documentation for PythonMagick. (yes I know, Kevin Cabazon wrote PIL_usm, but I could not get it to work, probably due to my inexperience. Anyway, this code makes it easy to convert back and forth from PIL to PythonMagick (maybe not such a good idea on a memory tight high loaded production server, but no problem on my private server (Pentium-M @ 1.8 Ghz with 1 GB Mem.) **usage:** usm takes a PIL image object. Radius and sigma is in pixels, amount 1 compares to 100% in photoshop, threshold 0.004 ~ (1/256) compares to 1 in photoshop: I'm using r=1,s=0.5,a=0.8,t=0.016 for roughly 800x600 images created from 3000x2000 (6MP) images. Experiment for your own preferences.

  • image
  • pil
  • sharpen
  • thumbnails
  • pythonmagick
  • usm
Read More

ImageWithThumbsField

Easy way to generate image thumbnails for your models. Works with any Storage Backend. From: [http://code.google.com/p/django-thumbs/](http://code.google.com/p/django-thumbs/) **Usage example:** ============== photo = ImageWithThumbsField(upload_to='images', sizes=((125,125),(300,200),) To retrieve image URL, exactly the same way as with ImageField: my_object.photo.url To retrieve thumbnails URL's just add the size to it: my_object.photo.url_125x125 my_object.photo.url_300x200 Note: The 'sizes' attribute is not required. If you don't provide it, ImageWithThumbsField will act as a normal ImageField **How it works:** ============= For each size in the 'sizes' atribute of the field it generates a thumbnail with that size and stores it following this format: available_filename.[width]x[height].extension Where 'available_filename' is the available filename returned by the storage backend for saving the original file. Following the usage example above: For storing a file called "photo.jpg" it saves: photo.jpg (original file) photo.125x125.jpg (first thumbnail) photo.300x200.jpg (second thumbnail) With the default storage backend if photo.jpg already exists it will use these filenames: photo_.jpg photo_.125x125.jpg photo_.300x200.jpg **Note:** It assumes that if filename "any_filename.jpg" is available filenames with this format "any_filename.[widht]x[height].jpg" will be available, too.

  • image
  • models
  • fields
  • thumbnail
  • field
  • thumbnails
  • thumbs
Read More

4 snippets posted so far.