Archived
1
0

* fix thumbnailing

* make thumbnailing programs configurable
This commit is contained in:
Jeff Becker 2016-11-06 08:08:34 -05:00
parent 8665b98452
commit cc957f3de5
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
2 changed files with 10 additions and 6 deletions

View File

@ -127,3 +127,7 @@ ASSETS_ROOT = os.path.join(BASE_DIR, 'assets')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
# for thumbnailing
CONVERT_PATH = '/usr/bin/convert'
FFMPEG_PATH = '/usr/bin/ffmpeg'

View File

@ -1,8 +1,8 @@
from django.conf import settings
import subprocess
import os
img_ext = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'ico']
vid_ext = ['mp4', 'webm', 'm4v', 'ogv', 'avi']
txt_ext = ['txt', 'pdf', 'ps']
img_ext = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'ico', 'pdf', 'ps']
vid_ext = ['mp4', 'webm', 'm4v', 'ogv', 'avi', 'txt']
def generate(fname, tname, placeholder):
"""
@ -11,9 +11,9 @@ def generate(fname, tname, placeholder):
ext = fname.split('.')[-1]
cmd = None
if ext in img_ext:
cmd = ['/usr/bin/convert', '-thumbnail', '200', fname, tname]
elif ext in vid_ext or ext in txt_ext:
cmd = ['/usr/bin/ffmpeg', '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
cmd = [settings.CONVERT_PATH, '-thumbnail', '200', fname, tname]
elif ext in vid_ext:
cmd = [settings.FFMPEG_PATH, '-i', fname, '-vf', 'scale=300:200', '-vframes', '1', tname]
if cmd is None:
os.link(placeholder, tname)