Skip to content

Commit d0d5c4b

Browse files
author
Logan Endes
committed
feat: support for m4a and mov, with some heic files supported, and nef in progress
1 parent 7208b04 commit d0d5c4b

6 files changed

Lines changed: 123 additions & 2 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ MAINTAINER Computer Science House <rtp@csh.rit.edu>
44
ENV IMAGEIO_USERDIR /var/lib/gallery
55

66
RUN apt-get update && \
7-
apt-get install -y libldap-dev libsasl2-dev libmagic-dev ghostscript libldap-common && \
7+
apt-get install -y libldap-dev libsasl2-dev libmagic-dev ghostscript libldap-common imagemagick libheif1 libheif-dev libraw-dev libraw20 dcraw && \
88
apt-get autoremove --yes && \
99
apt-get clean autoclean && \
1010
sed -i \

gallery/file_modules/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def generate_thumbnail(self):
6565
from gallery.file_modules.txt import TXTFile
6666
from gallery.file_modules.mp3 import MP3File
6767
from gallery.file_modules.wav import WAVFile
68+
from gallery.file_modules.heic import HEICFile
69+
from gallery.file_modules.nef import NEFFile
70+
from gallery.file_modules.mov import MOVFile
71+
from gallery.file_modules.m4a import M4AFile
6872

6973
file_mimetype_relation = {
7074
"image/jpeg": JPEGFile,
@@ -76,13 +80,18 @@ def generate_thumbnail(self):
7680
"image/x-windows-bmp": BMPFile,
7781
"image/tiff": TIFFFile,
7882
"image/x-tiff": TIFFFile,
83+
"image/heic": HEICFile,
84+
"image/x-nikon-nef": NEFFile,
7985
"video/mp4": MP4File,
8086
"video/webm": WebMFile,
8187
"video/ogg": OggFile,
88+
"video/quicktime": MOVFile,
8289
"application/pdf": PDFFile,
8390
"text/plain": TXTFile,
8491
"audio/mpeg": MP3File,
85-
"audio/x-wav": WAVFile
92+
"audio/x-wav": WAVFile,
93+
"audio/mp4": M4AFile,
94+
"audio/x-m4a": M4AFile,
8695
}
8796

8897

gallery/file_modules/heic.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import os
2+
from wand.image import Image
3+
from wand.color import Color
4+
5+
from gallery.file_modules import FileModule
6+
from gallery.util import hash_file
7+
8+
9+
class HEICFile(FileModule):
10+
def __init__(self, file_path, dir_path):
11+
FileModule.__init__(self, file_path, dir_path)
12+
self.mime_type = "image/heic"
13+
14+
self.generate_thumbnail()
15+
16+
def generate_thumbnail(self):
17+
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"
18+
19+
with Image(filename=self.file_path) as img:
20+
with Image(width=img.width, height=img.height, background=Color("#EEEEEE")) as bg:
21+
# Fix orientation from EXIF
22+
img.auto_orient()
23+
# Force proper colorspace conversion
24+
img.transform_colorspace('srgb')
25+
# Remove alpha if present
26+
img.alpha_channel = 'remove'
27+
# Strip ICC/HDR metadata (prevents weird color shifts)
28+
img.strip()
29+
# Same process as other image types
30+
bg.composite(img, 0, 0)
31+
size = img.width if img.width < img.height else img.height
32+
bg.crop(width=size, height=size, gravity='center')
33+
bg.resize(256, 256)
34+
bg.format = 'jpeg'
35+
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))

gallery/file_modules/m4a.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import os
2+
from wand.image import Image
3+
4+
from gallery.file_modules import FileModule
5+
from gallery.util import hash_file
6+
7+
class M4AFile(FileModule):
8+
def __init__(self, file_path, dir_path):
9+
FileModule.__init__(self, file_path, dir_path)
10+
self.mime_type = "audio/mp4"
11+
12+
self.generate_thumbnail()
13+
14+
def generate_thumbnail(self):
15+
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"
16+
17+
with Image(filename="thumbnails/reedphoto.jpg") as bg:
18+
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))

gallery/file_modules/mov.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from moviepy.editor import VideoFileClip
2+
import os
3+
from wand.image import Image
4+
from wand.color import Color
5+
6+
from gallery.file_modules import FileModule
7+
from gallery.util import hash_file
8+
9+
10+
class MOVFile(FileModule):
11+
12+
def __init__(self, file_path, dir_path):
13+
FileModule.__init__(self, file_path, dir_path)
14+
self.mime_type = "video/quicktime"
15+
16+
self.generate_thumbnail()
17+
18+
def generate_thumbnail(self):
19+
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"
20+
thumbnail_loc = os.path.join(self.dir_path, self.thumbnail_uuid)
21+
22+
clip = VideoFileClip(self.file_path)
23+
time_mark = clip.duration * 0.05
24+
clip.save_frame(thumbnail_loc, t=time_mark)
25+
26+
with Image(filename=thumbnail_loc) as img:
27+
with img.clone() as image:
28+
size = image.width if image.width < image.height else image.height
29+
image.crop(width=size, height=size, gravity='center')
30+
image.resize(256, 256)
31+
image.background_color = Color("#EEEEEE")
32+
image.format = 'jpeg'
33+
image.save(filename=thumbnail_loc)

gallery/file_modules/nef.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
from wand.image import Image
3+
from wand.color import Color
4+
5+
from gallery.file_modules import FileModule
6+
from gallery.util import hash_file
7+
8+
9+
class NEFFile(FileModule):
10+
def __init__(self, file_path, dir_path):
11+
FileModule.__init__(self, file_path, dir_path)
12+
self.mime_type = "image/x-nikon-nef"
13+
14+
self.generate_thumbnail()
15+
16+
def generate_thumbnail(self):
17+
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"
18+
19+
with Image(filename=self.file_path) as img:
20+
with Image(width=img.width, height=img.height, background=Color("#EEEEEE")) as bg:
21+
bg.composite(img, 0, 0)
22+
size = img.width if img.width < img.height else img.height
23+
bg.crop(width=size, height=size, gravity='center')
24+
bg.resize(256, 256)
25+
bg.format = 'jpeg'
26+
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))

0 commit comments

Comments
 (0)