Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable HEIC files #77

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gallery/file_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def generate_thumbnail(self):
from gallery.file_modules.cr2 import CR2File
from gallery.file_modules.png import PNGFile
from gallery.file_modules.gif import GIFFile
from gallery.file_modules.heic import HEICFile
from gallery.file_modules.bmp import BMPFile
from gallery.file_modules.tiff import TIFFFile
from gallery.file_modules.mp4 import MP4File
Expand All @@ -70,6 +71,7 @@ def generate_thumbnail(self):
"image/x-canon-cr2": CR2File,
"image/png": PNGFile,
"image/gif": GIFFile,
"image/heic": HEICFILE,
"image/bmp": BMPFile,
"image/x-ms-bmp": BMPFile,
"image/x-windows-bmp": BMPFile,
Expand Down
27 changes: 27 additions & 0 deletions gallery/file_modules/heic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
from wand.image import Image
from wand.color import Color

from gallery.file_modules import FileModule
from gallery.util import hash_file


class HEICFile(FileModule):

def __init__(self, file_path, dir_path):
FileModule.__init__(self, file_path, dir_path)
self.mime_type = "image/heic"

self.generate_thumbnail()

def generate_thumbnail(self):
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"

with Image(filename=self.file_path) as img:
with Image(width=img.width, height=img.height, background=Color("#EEEEEE")) as bg:
bg.composite(img, 0, 0)
size = img.width if img.width < img.height else img.height
bg.crop(width=size, height=size, gravity='center')
bg.resize(256, 256)
bg.format = 'jpeg'
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))