#4115: contrib.thumbnails
---------------------------+------------------------------------------------
Reporter: SmileyChris | Owner: adrian
Status: new | Component: Contrib apps
Version: SVN | Resolution:
Keywords: | Stage: Design decision needed
Has_patch: 1 | Needs_docs: 0
Needs_tests: 1 | Needs_better_patch: 0
---------------------------+------------------------------------------------
Comment (by Chris Moffitt <[EMAIL PROTECTED]>):
The size is going to be returned incorrectly if a thumbnail is created.
Here's a simple function I created to cache and return the actual size.
I'd recommend calling this in the img_tag filter.
size_cache = get_cache('locmem:///')
_SIZE_CACHE_TIMEOUT = 60 * 60 * 60 * 24 * 31 # 1 month
def get_actual_size(self):
"""
When an image is scaled, the dimensions of the image may not equal
the supplied. Example 240x240 -> 240x96 actual size depending on
the aspect
ratio. This uses the cache to store the actual size instead of
calling it each
time an image is displayed. Normal use case is for image tags.
"""
size = size_cache.get(self.filename)
if size:
return size
try:
img = Image.open(self.filename)
size_cache.set(self.filename, im.size, _SIZE_CACHE_TIMEOUT)
return img.size
except IOError, msg:
raise ThumbnailInvalidImage(msg)
actual_size = property(get_actual_size)
--
Ticket URL: <http://code.djangoproject.com/ticket/4115#comment:12>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---