|
|
@ -7,9 +7,11 @@ from django.utils import timezone |
|
|
|
from django.utils.encoding import force_unicode |
|
|
|
|
|
|
|
from PIL import Image |
|
|
|
from PIL.ExifTags import TAGS |
|
|
|
import os |
|
|
|
from cStringIO import StringIO |
|
|
|
from django.core.files.base import ContentFile |
|
|
|
from datetime import datetime |
|
|
|
|
|
|
|
from seminar.models import Soustredeni |
|
|
|
|
|
|
@ -22,6 +24,33 @@ VIDITELNOST = ( |
|
|
|
(NIKDY, 'Nikdy'), |
|
|
|
) |
|
|
|
|
|
|
|
def get_exif(fn): |
|
|
|
ret = {} |
|
|
|
info = fn._getexif() |
|
|
|
for tag, value in info.items(): |
|
|
|
decoded = TAGS.get(tag, tag) |
|
|
|
ret[decoded] = value |
|
|
|
return ret |
|
|
|
|
|
|
|
def flip_horizontal(im): return im.transpose(Image.FLIP_LEFT_RIGHT) |
|
|
|
def flip_vertical(im): return im.transpose(Image.FLIP_TOP_BOTTOM) |
|
|
|
def rotate_180(im): return im.transpose(Image.ROTATE_180) |
|
|
|
def rotate_90(im): return im.transpose(Image.ROTATE_90) |
|
|
|
def rotate_270(im): return im.transpose(Image.ROTATE_270) |
|
|
|
def transpose(im): return rotate_90(flip_horizontal(im)) |
|
|
|
def transverse(im): return rotate_90(flip_vertical(im)) |
|
|
|
orientation_funcs = [None, |
|
|
|
lambda x: x, |
|
|
|
flip_horizontal, |
|
|
|
rotate_180, |
|
|
|
flip_vertical, |
|
|
|
transpose, |
|
|
|
rotate_270, |
|
|
|
transverse, |
|
|
|
rotate_90 |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
def obrazek_filename(self, filename): |
|
|
|
return obrazek_filename_obecny(self, filename, "velky") |
|
|
|
|
|
|
@ -57,6 +86,21 @@ class Obrazek(models.Model): |
|
|
|
verbose_name_plural = 'Obrázky' |
|
|
|
def save(self): |
|
|
|
original = Image.open(self.obrazek_velky) |
|
|
|
# vycteni EXIFu |
|
|
|
exif = get_exif(original) |
|
|
|
if exif['Orientation']: |
|
|
|
f = orientation_funcs[exif['Orientation']] |
|
|
|
original_otoceny = f(original) |
|
|
|
original_otoceny.format = original.format |
|
|
|
original = original_otoceny |
|
|
|
# datum podle EXIfu |
|
|
|
if exif['DateTimeOriginal']: |
|
|
|
datum_string = ":".join(exif['DateTimeOriginal'].split(' ')).split(":") |
|
|
|
datum_int = [] |
|
|
|
for retezec in datum_string: |
|
|
|
datum_int.append(int(retezec)) |
|
|
|
self.datum = datetime(datum_int[0], datum_int[1], datum_int[2], |
|
|
|
datum_int[3], datum_int[4], datum_int[5]) |
|
|
|
jmeno = os.path.basename(self.obrazek_velky.file.name) |
|
|
|
if not self.obrazek_stredni: |
|
|
|
Obrazek._vyrobMiniaturu(original, jmeno, 500, self.obrazek_stredni) |
|
|
|