* fix thumbnailing
* make thumbnailing programs configurable
This commit is contained in:
parent
8665b98452
commit
cc957f3de5
@ -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'
|
||||
|
@ -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)
|
||||
|
Reference in New Issue
Block a user