frames
This commit is contained in:
parent
9ba3e58f33
commit
36da96c8e0
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/data/
|
||||||
11
Event.py
11
Event.py
@ -4,7 +4,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from config import pil_image_to_surface, WIDTH, HEIGHT, SCREEN_RECT, DOMAIN, THUMB_WIDTH, THUMB_HEIGHT
|
from config import pil_image_to_surface, WIDTH, HEIGHT, SCREEN_RECT, DOMAIN, PHOTO_WIDTH, PHOTO_HEIGHT
|
||||||
|
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
@ -15,8 +15,8 @@ class Event:
|
|||||||
self.date = datetime.strptime(data['date'], '%Y-%m-%d')
|
self.date = datetime.strptime(data['date'], '%Y-%m-%d')
|
||||||
self.password = data['password']
|
self.password = data['password']
|
||||||
self.frame_factor = float(data['frame_factor']) if 'frame_factor' in data else 1.0
|
self.frame_factor = float(data['frame_factor']) if 'frame_factor' in data else 1.0
|
||||||
self.frame_original = Image.open("./data/frames/" + data['frame'])
|
self.frame_photo_sized = shrink_cover(Image.open("./data/frames/" + data['frame']), PHOTO_WIDTH, PHOTO_HEIGHT)
|
||||||
self.frame = pil_image_to_surface(shrink_cover(self.frame_original, int(WIDTH * self.frame_factor), int(HEIGHT * self.frame_factor)))
|
self.frame = pil_image_to_surface(shrink_cover(self.frame_photo_sized, int(WIDTH * self.frame_factor), int(HEIGHT * self.frame_factor)))
|
||||||
self.frame_rect = self.frame.get_rect(center=SCREEN_RECT.center)
|
self.frame_rect = self.frame.get_rect(center=SCREEN_RECT.center)
|
||||||
self.url_without_protocol = "%s/e/%s" % (DOMAIN, self.code)
|
self.url_without_protocol = "%s/e/%s" % (DOMAIN, self.code)
|
||||||
|
|
||||||
@ -53,3 +53,8 @@ def shrink_cover(img: Image, width: float, height: float):
|
|||||||
h = height
|
h = height
|
||||||
w = height * r
|
w = height * r
|
||||||
return img.resize((int(w), int(h)), Image.Resampling.LANCZOS)
|
return img.resize((int(w), int(h)), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
|
||||||
|
def _resize2(img: Image, width: float):
|
||||||
|
height = width / img.width * img.height
|
||||||
|
return img.resize((int(width), int(height)), Image.Resampling.LANCZOS)
|
||||||
|
|||||||
26
Fotobox.py
26
Fotobox.py
@ -163,7 +163,7 @@ class Fotobox:
|
|||||||
if self._choice is not None:
|
if self._choice is not None:
|
||||||
screen.blit(SAVE_SURFACE, SAVE_RECT)
|
screen.blit(SAVE_SURFACE, SAVE_RECT)
|
||||||
for photo in self._photos:
|
for photo in self._photos:
|
||||||
screen.blit(photo.thumb, photo.thumb_rect)
|
screen.blit(photo.thumb_surface, photo.thumb_rect)
|
||||||
if self._choice == photo:
|
if self._choice == photo:
|
||||||
rect = pygame.Rect(
|
rect = pygame.Rect(
|
||||||
photo.thumb_rect.x - CHOICE_BORDER,
|
photo.thumb_rect.x - CHOICE_BORDER,
|
||||||
@ -174,7 +174,7 @@ class Fotobox:
|
|||||||
pygame.draw.rect(screen, (0, 255, 0), rect, width=CHOICE_BORDER)
|
pygame.draw.rect(screen, (0, 255, 0), rect, width=CHOICE_BORDER)
|
||||||
elif self._state == State.QR:
|
elif self._state == State.QR:
|
||||||
screen.blit(self._qr, self._qr_rect)
|
screen.blit(self._qr, self._qr_rect)
|
||||||
screen.blit(self._choice.chosen, self._choice.chosen_rect)
|
screen.blit(self._choice.chosen_surface, self._choice.chosen_rect)
|
||||||
if self._printer is not None and not self._printed:
|
if self._printer is not None and not self._printed:
|
||||||
screen.blit(PRINT_SURFACE, PRINT_RECT)
|
screen.blit(PRINT_SURFACE, PRINT_RECT)
|
||||||
screen.blit(DONE_SURFACE, DONE_RECT)
|
screen.blit(DONE_SURFACE, DONE_RECT)
|
||||||
@ -214,7 +214,11 @@ class Fotobox:
|
|||||||
self._qr = qr_create(self._choice.urlWithProtocol)
|
self._qr = qr_create(self._choice.urlWithProtocol)
|
||||||
self._qr_rect = self._qr.get_rect(left=2 * BORDER, centery=SCREEN_RECT.centery)
|
self._qr_rect = self._qr.get_rect(left=2 * BORDER, centery=SCREEN_RECT.centery)
|
||||||
|
|
||||||
filename = "F-%s---R%04d-%s---S%04d-%s---P%04d-%s---%s.jpg" % (
|
self.save(self._choice.photo_image, "")
|
||||||
|
self.save(self._choice.framed_image, "framed")
|
||||||
|
|
||||||
|
def save(self, img: Image, suffix: str):
|
||||||
|
filename = "F-%s---R%04d-%s---S%04d-%s---P%04d-%s---%s%s.jpg" % (
|
||||||
self._fotobox_uuid,
|
self._fotobox_uuid,
|
||||||
self._runtime_number,
|
self._runtime_number,
|
||||||
iso(self._runtime_datetime),
|
iso(self._runtime_datetime),
|
||||||
@ -223,21 +227,17 @@ class Fotobox:
|
|||||||
self._choice.number,
|
self._choice.number,
|
||||||
iso(self._choice.datetime),
|
iso(self._choice.datetime),
|
||||||
self._choice.code,
|
self._choice.code,
|
||||||
|
"---" + suffix if suffix != "" else ""
|
||||||
)
|
)
|
||||||
|
path = Path("./data/photos/original/F-%s/R%04d-%s/%s" % (
|
||||||
original = Path("./data/photos/original/F-%s/R%04d-%s/%s" % (
|
|
||||||
self._fotobox_uuid,
|
self._fotobox_uuid,
|
||||||
|
|
||||||
self._runtime_number,
|
self._runtime_number,
|
||||||
iso(self._runtime_datetime),
|
iso(self._runtime_datetime),
|
||||||
|
|
||||||
filename,
|
filename,
|
||||||
))
|
))
|
||||||
original.parent.mkdir(parents=True, exist_ok=True)
|
path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
self._choice.img.save(original, format='JPEG', quality=95)
|
img.save(path, format='JPEG', quality=95)
|
||||||
|
|
||||||
upload = Path("./data/photos/upload/%s" % (filename,))
|
upload = Path("./data/photos/upload/%s" % (filename,))
|
||||||
upload.parent.mkdir(parents=True, exist_ok=True)
|
upload.parent.mkdir(parents=True, exist_ok=True)
|
||||||
os.link(original, upload)
|
os.link(path, upload)
|
||||||
|
print("Photo saved: %s" % path.absolute())
|
||||||
print("Photo saved: %s" % original.absolute())
|
|
||||||
|
|||||||
41
Photo.py
41
Photo.py
@ -1,10 +1,7 @@
|
|||||||
from datetime import datetime
|
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pygame import Surface
|
|
||||||
|
|
||||||
from Event import Event, shrink_inside
|
from Event import Event, shrink_inside
|
||||||
from config import THUMB_WIDTH, pil_image_to_surface, SCREEN_RECT, BORDER, WIDTH, now, generate_code, HTTPS, DOMAIN, THUMB_HEIGHT
|
from config import THUMB_WIDTH, pil_image_to_surface, SCREEN_RECT, BORDER, now, generate_code, HTTPS, DOMAIN, PHOTO_HEIGHT
|
||||||
|
|
||||||
|
|
||||||
class Photo:
|
class Photo:
|
||||||
@ -15,31 +12,25 @@ class Photo:
|
|||||||
self.code = generate_code(4)
|
self.code = generate_code(4)
|
||||||
self.urlWithoutProtocol = "%s/p/%s" % (DOMAIN, self.code)
|
self.urlWithoutProtocol = "%s/p/%s" % (DOMAIN, self.code)
|
||||||
self.urlWithProtocol = "http%s://%s" % ('s' if HTTPS else '', self.urlWithoutProtocol)
|
self.urlWithProtocol = "http%s://%s" % ('s' if HTTPS else '', self.urlWithoutProtocol)
|
||||||
self.img = img
|
self.photo_image = img
|
||||||
self.thumb = None
|
self.framed_image = None
|
||||||
|
self.thumb_surface = None
|
||||||
self.thumb_rect = None
|
self.thumb_rect = None
|
||||||
self.chosen = None
|
self.chosen_surface = None
|
||||||
self.chosen_rect = None
|
self.chosen_rect = None
|
||||||
|
|
||||||
def prepare(self, event: Event):
|
def prepare(self, event: Event):
|
||||||
frame = self._resize2(event.frame_original, THUMB_WIDTH)
|
self.framed_image = Image.new('RGB', (event.frame_photo_sized.width, event.frame_photo_sized.height))
|
||||||
photo = shrink_inside(self.img, frame.width / (event.frame_factor - 0.01), frame.height / (event.frame_factor - 0.01))
|
pos = ((self.framed_image.width - self.photo_image.width) // 2, (self.framed_image.height - self.photo_image.height) // 2)
|
||||||
self.thumb = Surface((frame.width, frame.height))
|
self.framed_image.paste(self.photo_image, pos, self.photo_image.convert('RGBA'))
|
||||||
self.thumb.blit(pil_image_to_surface(photo), ((frame.width - photo.width) / 2, (frame.height - photo.height) / 2))
|
self.framed_image.paste(event.frame_photo_sized, (0, 0), event.frame_photo_sized)
|
||||||
self.thumb.blit(pil_image_to_surface(frame), (0, 0))
|
|
||||||
self.thumb_rect = self.thumb.get_rect(centery=SCREEN_RECT.centery, left=(self.number - 1) * (THUMB_WIDTH + BORDER) + BORDER)
|
|
||||||
|
|
||||||
frame_chosen = self._resize2(event.frame_original, THUMB_WIDTH)
|
self.thumb_surface = pil_image_to_surface(shrink_inside(self.framed_image, THUMB_WIDTH, PHOTO_HEIGHT))
|
||||||
photo_chosen = shrink_inside(self.img, frame_chosen.width / event.frame_factor, frame_chosen.height / event.frame_factor)
|
self.thumb_rect = self.thumb_surface.get_rect(centery=SCREEN_RECT.centery, left=(self.number - 1) * (THUMB_WIDTH + BORDER) + BORDER)
|
||||||
self.chosen = Surface((frame_chosen.width, frame_chosen.height))
|
|
||||||
self.chosen.blit(pil_image_to_surface(photo_chosen), ((frame_chosen.width - photo_chosen.width) / 2, (frame_chosen.height - photo_chosen.height) / 2))
|
self.chosen_surface = pil_image_to_surface(shrink_inside(self.framed_image, THUMB_WIDTH, PHOTO_HEIGHT))
|
||||||
self.chosen.blit(pil_image_to_surface(frame_chosen), (0, 0))
|
self.chosen_rect = self.thumb_surface.get_rect(centery=SCREEN_RECT.centery, left=(self.number - 1) * (THUMB_WIDTH + BORDER) + BORDER)
|
||||||
self.chosen_rect = self.chosen.get_rect(right=WIDTH - 2 * BORDER, centery=SCREEN_RECT.centery)
|
|
||||||
|
|
||||||
def _resize(self, width: float):
|
def _resize(self, width: float):
|
||||||
height = width / self.img.width * self.img.height
|
height = width / self.photo_image.width * self.photo_image.height
|
||||||
return self.img.resize((int(width), int(height)), Image.Resampling.LANCZOS)
|
return self.photo_image.resize((int(width), int(height)), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
def _resize2(self, img: Image, width: float):
|
|
||||||
height = width / img.width * img.height
|
|
||||||
return img.resize((int(width), int(height)), Image.Resampling.LANCZOS)
|
|
||||||
|
|||||||
@ -15,6 +15,9 @@ WIDTH: int = 800
|
|||||||
HEIGHT: int = 480
|
HEIGHT: int = 480
|
||||||
BORDER: int = 10
|
BORDER: int = 10
|
||||||
|
|
||||||
|
PHOTO_WIDTH = 2592
|
||||||
|
PHOTO_HEIGHT = 1944
|
||||||
|
|
||||||
SHOOTING_COUNT: int = 2
|
SHOOTING_COUNT: int = 2
|
||||||
SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75
|
SHOOTING_INTERVAL: float = 0 if DEBUG else 1.75
|
||||||
COUNTDOWN_COUNT: int = 1 if DEBUG else 3
|
COUNTDOWN_COUNT: int = 1 if DEBUG else 3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user