mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
22 lines
550 B
Python
22 lines
550 B
Python
""" ImageKit utility functions """
|
|
|
|
import tempfile
|
|
|
|
def img_to_fobj(img, format, **kwargs):
|
|
tmp = tempfile.TemporaryFile()
|
|
img.convert('RGB').save(tmp, format, **kwargs)
|
|
tmp.seek(0)
|
|
return tmp
|
|
|
|
|
|
def get_spec_files(instance):
|
|
from imagekit.fields import ImageSpecFile
|
|
spec_files = []
|
|
for key in dir(instance):
|
|
try:
|
|
value = getattr(instance, key)
|
|
except AttributeError:
|
|
continue
|
|
if isinstance(value, ImageSpecFile):
|
|
spec_files.append(value)
|
|
return spec_files
|