Skip to content

Instantly share code, notes, and snippets.

@dahlia
Created November 28, 2012 15:22
Show Gist options
  • Save dahlia/4161930 to your computer and use it in GitHub Desktop.
Save dahlia/4161930 to your computer and use it in GitHub Desktop.
Django monkeypatch for Wand
from django.core.files import images
def get_image_dimensions(file_or_path, close=False):
if hasattr(file_or_path, 'read'):
arg_name = 'file'
file = True
filepos = file_or_path.tell() if hasattr(file_or_path, 'tell') else 0
else:
arg_name = 'filename'
file = False
try:
image = Image(**{arg_name: file_or_path})
return image.size
finally:
if file:
if close:
file_or_path.close()
else:
file_or_path.seek(filepos)
images.get_image_dimensions = get_image_dimensions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment