diff options
Diffstat (limited to 'app/photos/forms.py')
-rw-r--r-- | app/photos/forms.py | 55 |
1 files changed, 9 insertions, 46 deletions
diff --git a/app/photos/forms.py b/app/photos/forms.py index 1f80496..8ad89f2 100644 --- a/app/photos/forms.py +++ b/app/photos/forms.py @@ -2,10 +2,8 @@ import zipfile from zipfile import BadZipFile import logging import datetime -import time import os from io import BytesIO -from fractions import Fraction try: import Image except ImportError: @@ -17,21 +15,18 @@ from django.utils.safestring import mark_safe from django.contrib import messages from django.core.files.base import ContentFile from django.contrib.admin import widgets -from django.contrib.gis.geos import Point from django.conf import settings -import exiftool -from photos.models import LuxImage, LuxGallery -from locations.models import Location +from photos.models import LuxImage, LuxGallery, LuxImageSize from .utils import resize_image +from .readexif import readexif logger = logging.getLogger('photos.forms') class GalleryForm(forms.ModelForm): class Meta: - model = LuxGallery fields = '__all__' widgets = { 'images': forms.SelectMultiple, @@ -152,56 +147,24 @@ class UploadZipForm(forms.Form): image.image.save(filename, contentfile) image.save() gallery.images.add(image) - - with exiftool.ExifTool() as et: - meta = et.get_metadata(image.image.path) - et.terminate() - image.exif_raw = meta - try: - image.title = meta["EXIF:ImageDescription"] - except: - pass - try: - image.caption = meta["EXIF:UserComment"] - except: - pass - try: - image.exif_lens = meta["MakerNotes:LensType"] - except: - try: - image.exif_lens = meta["XMP:Lens"] - except: - pass - try: - image.point = Point(meta["XMP:GPSLongitude"], meta["XMP:GPSLatitude"], srid=4326) - try: - image.location = Location.objects.filter(geometry__contains=image.point).get() - except Location.DoesNotExist: - pass - except KeyError: - pass - image.exif_aperture = meta["EXIF:FNumber"] - image.exif_make = meta["EXIF:Make"] - image.exif_model = meta["EXIF:Model"] - image.exif_exposure = str(Fraction(float(meta["EXIF:ExposureTime"])).limit_denominator()) - image.exif_iso = meta["EXIF:ISO"] - image.exif_focal_length = meta["EXIF:FocalLength"] - fmt_date = time.strptime(meta["EXIF:DateTimeOriginal"], "%Y:%m:%d %H:%M:%S") - image.exif_date = time.strftime("%Y-%m-%d %H:%M:%S", fmt_date) - image.height = meta["File:ImageHeight"] - image.width = meta["File:ImageWidth"] - image.save() + readexif(image) count += 1 img = Image.open(image.image.path) base_path = "%s/galleries/" % settings.IMAGES_ROOT if img.size[0] > img.size[1]: resize_image(img, 2280, None, 65, base_path+'large/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=2280)) resize_image(img, 1140, None, 72, base_path+'medium/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=1140)) resize_image(img, 720, None, 68, base_path+'small/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=720)) if img.size[1] > img.size[0]: resize_image(img, None, 1600, 65, base_path+'large/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=1600)) resize_image(img, None, 800, 72, base_path+'medium/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=800)) resize_image(img, None, 460, 60, base_path+'small/', image.get_image_name()) + image.sizes.add(LuxImageSize.objects.get(size=460)) resize_image(img, 160, None, 68, base_path+'thumb/', image.get_image_name()) zipper.close() |