Skip to content

Instantly share code, notes, and snippets.

@gengue
Last active February 11, 2017 17:31
Show Gist options
  • Save gengue/74ecc1792e3ca645f4f38f89469297e4 to your computer and use it in GitHub Desktop.
Save gengue/74ecc1792e3ca645f4f38f89469297e4 to your computer and use it in GitHub Desktop.
Unescape special chars in Django VersatileImage
#python3.5/versatileimagefield/datastructures/base.py
# -*- coding: utf-8 -*-
def retrieve_image(self, path_to_image):
"""Return a PIL Image instance stored at `path_to_image`."""
from urllib.parse import unquote
image = self.storage.open(unquote(path_to_image), 'rb')
file_ext = path_to_image.rsplit('.')[-1]
image_format, mime_type = get_image_metadata_from_file_ext(file_ext)
return (
Image.open(image),
file_ext,
image_format,
mime_type
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment