galerie | vycteni EXIFu + razeni fotek podle casu
vycteni EXIFu -- otoceni fotky podle udaje z EXIFu -- prirazeni datumu podle udaje z EXIFu razeni fotek podle datumu
This commit is contained in:
parent
531506b798
commit
fd8aff5aff
4 changed files with 52 additions and 27 deletions
|
@ -3,8 +3,6 @@
|
|||
|======|
|
||||
|
||||
Aktualni
|
||||
* vycteni EXIFu (datum)
|
||||
* razeni podle casu
|
||||
* třízení podgalerií
|
||||
* predelat URL na cistsi (odstranit probehlo)
|
||||
* do CSS
|
||||
|
@ -15,5 +13,7 @@ Dlouhodobe
|
|||
|
||||
Fylozoficke
|
||||
* zvolit velikosti velke a male fotky
|
||||
* spravne otoceni fyzicky neotocenych fotek
|
||||
* je potreba i jine razeni nez automaticky podle casu nebo staci podgalerie?
|
||||
* napr. dve hry na dvou ruznych mistech ve stejny cas
|
||||
* fotky od ucastniku ze hry (skupinky se pohybuji ve stejny cas, ale maji sled fotek) -- nestaci to pripadne vrazit do podgalerii?
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
{% endif %}
|
||||
|
||||
{# obrazky v galerii #}
|
||||
{% if galerie.obrazek_set.all %}
|
||||
{% if obrazky %}
|
||||
<table class="galerie_nahled">
|
||||
{% for obrazek in galerie.obrazek_set.all %}
|
||||
{% for obrazek in obrazky %}
|
||||
{% if forloop.counter|add:-1|divisibleby:3 %}
|
||||
<tr>
|
||||
{% endif %}
|
||||
|
|
|
@ -11,25 +11,6 @@ from galerie.models import Obrazek, Galerie
|
|||
from seminar.models import Soustredeni
|
||||
from galerie.forms import KomentarForm, NewGalerieForm
|
||||
|
||||
|
||||
#def index(request, stitek=None):
|
||||
#if stitek == None:
|
||||
#return HttpResponseRedirect('./0/')
|
||||
#
|
||||
#galerie = Galerie.publikovane_galerie()
|
||||
#if int(stitek) != 0:
|
||||
#galerie = galerie.filter(stitek = stitek)
|
||||
#if not galerie:
|
||||
#raise Http404
|
||||
#galerie = galerie.order_by("-datum_zmeny")
|
||||
#
|
||||
#return render(request, 'Galerie/GalerieIndex.html',
|
||||
#{'galerie' : galerie,
|
||||
#'stitky' : Stitek.stitky_u_galerii(),
|
||||
#'umisteni_stitek' : stitek,
|
||||
#'umisteni_Fotogalerie' : True,
|
||||
#})
|
||||
|
||||
def zobrazit(galerie, request):
|
||||
preview = False
|
||||
if galerie.zobrazit >= 1:
|
||||
|
@ -39,13 +20,14 @@ def zobrazit(galerie, request):
|
|||
raise Http404
|
||||
return preview
|
||||
|
||||
|
||||
def nahled(request, pk, soustredeni):
|
||||
"""Zobrazeni nahledu vsech fotek ve skupine."""
|
||||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
obrazky = Obrazek.objects.filter(galerie = galerie).order_by('datum')
|
||||
preview = zobrazit(galerie, request)
|
||||
return render(request, 'galerie/GalerieNahled.html',
|
||||
{'galerie' : galerie,
|
||||
'obrazky' : obrazky,
|
||||
'preview' : preview,
|
||||
})
|
||||
|
||||
|
@ -60,7 +42,7 @@ def detail(request, pk, fotka, soustredeni):
|
|||
galerie = get_object_or_404(Galerie, pk=pk)
|
||||
preview = zobrazit(galerie, request)
|
||||
obrazek = get_object_or_404(Obrazek, pk=fotka)
|
||||
obrazky = galerie.obrazek_set.all()
|
||||
obrazky = galerie.obrazek_set.all().order_by('datum')
|
||||
|
||||
# vytvoreni a obslouzeni formulare
|
||||
if request.method == 'POST':
|
||||
|
@ -146,7 +128,6 @@ def new_galerie(request, galerie, soustredeni):
|
|||
o = Obrazek()
|
||||
o.obrazek_velky = obr
|
||||
o.nazev = str(obr)
|
||||
o.datum = datetime.now() #TODO vycist z EXIFU
|
||||
o.galerie = gal
|
||||
o.save()
|
||||
|
||||
|
|
Loading…
Reference in a new issue