DISQUS

DISQUS Hello! Code Spatter is using DISQUS, a powerful comment system, to manage its comments. Learn more.

Community Page

Jump to original thread »
Author

Quick Thumbnails in Django

Started by Greg Allard · 9 ヶ月 ago

I normally like to write code myself instead of installing some large script just to do one task for me. There were a few scripts out there that could create thumbnails, but I wanted something simple and wouldn’t use most of those features. Plus, I wanted to know how to use the Pytho ... Continue reading »

9 comments

  • I am doing a small project in Django (I'm a Python newbie, learning as I go). I initially wanted to deal with thumbnails, but finally skipped it, since was not really relevant to the project. But I'll definitely try this when I start working on improvements.

    Thanks for sharing! :)
  • I hope it helps you out when you need it. I just started learning django and python when trying to figure this out and that is probably why it took me a while.
  • Take a look at this snippets:

    http://www.djangosnippets.org/snippets/192/

    Thumbnails are generated in a lazy way. I like the idea.
  • I'll probably stick with my method since it gets the processing done initially and avoids the case where many images all need to be resized on a single page load.

    Although, having a filter to do that will be convenient if you change your mind on the thumbnail size.
  • I'm all for writing a little code to understand a library like PIL. It's worth noting sorl-thumbnail (http://code.google.com/p/sorl-thumbnail/), however, as a django app that solves just this problem... It can do a lot of things but at the simplest level you can just use a template tag to specify the thumbnail size and thumbnails are generated and cached for future use. A very nice app...
  • Thanks for the link. I will probably check that out since I know I will want more features at some point.
  • Thank you for the StringIO tip, it saved my time :-)
  • I'm glad this helped. That was the hardest part to figure out. I didn't want to create a temporary file on the file system and StringIO wasn't the first thing I tried.
  • I updated this post. I was thinking the uploaded file was deleted after using it, but I just needed to reset the file. Django's InMemoryUploadedFile uses StringIO. Doing file.seek(0)
    will reset the StringIO file to be ready to create another thumbnail.

Add New Comment

Returning? Login