mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-04-24 15:04:43 +00:00
Add util for generating named image file
This commit is contained in:
parent
4f7ce68904
commit
a499f5fbe6
1 changed files with 11 additions and 2 deletions
|
|
@ -3,11 +3,12 @@ import os
|
|||
from django.core.files.base import ContentFile
|
||||
|
||||
from imagekit.lib import Image, StringIO
|
||||
from tempfile import NamedTemporaryFile
|
||||
from .models import Photo
|
||||
import pickle
|
||||
|
||||
|
||||
def get_image_file():
|
||||
def _get_image_file(file_factory):
|
||||
"""
|
||||
See also:
|
||||
|
||||
|
|
@ -16,12 +17,20 @@ def get_image_file():
|
|||
|
||||
"""
|
||||
path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'assets', 'lenna-800x600-white-border.jpg')
|
||||
tmp = StringIO()
|
||||
tmp = file_factory()
|
||||
tmp.write(open(path, 'r+b').read())
|
||||
tmp.seek(0)
|
||||
return tmp
|
||||
|
||||
|
||||
def get_image_file():
|
||||
return _get_image_file(StringIO)
|
||||
|
||||
|
||||
def get_named_image_file():
|
||||
return _get_image_file(NamedTemporaryFile)
|
||||
|
||||
|
||||
def create_image():
|
||||
return Image.open(get_image_file())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue