easy-thumbnails icon indicating copy to clipboard operation
easy-thumbnails copied to clipboard

Generating thumbnail from URL

Open tejinderss opened this issue 13 years ago • 2 comments

Currently there is no way to generate a thumbnail from the file fetched through URL (external source).

tejinderss avatar Jun 03 '13 12:06 tejinderss

Looking forward to this feature as well. Currently working on a work around.

csantosdev avatar Aug 05 '13 20:08 csantosdev

easy-thumbnails can create a thumbnail from any file-like object.

The thumbnail won't be cached against this external source, but you can still generate the thumbnailed image.

import StringIO
import urllib2
import urlparse
from easy_thumbnails.files import get_thumbnailer

url = 'http://python.org/images/python-logo.gif'
p = urlparse.urlparse(url)
source = StringIO(urllib2.urlopen(url).read)
thumbnailer = get_thumbnailer(source, related_name=p.netloc + path)

opts = {'size': (30, 30)}
# This will just give you a file you can save somewhere
thumb = thumbnailer.build_thumbnail(opts)
# Or alternately, this will save the thumbnail to your media_root as:
# 'python.org/images/python-logo.gif.30x30_q85.png'
thumb = thumbnailer.get_thumbnail(opts)

SmileyChris avatar Aug 06 '13 01:08 SmileyChris