misc: use poppler to create PDF thumbnails (#34492)
This commit is contained in:
parent
569667e889
commit
3db2829e6e
|
@ -28,7 +28,7 @@ Recommends: python-dns,
|
|||
python-qrcode,
|
||||
python-magic,
|
||||
python-docutils,
|
||||
graphicsmagick
|
||||
poppler-utils
|
||||
Suggests: python-libxml2,
|
||||
python-lasso,
|
||||
python-psycopg2
|
||||
|
|
|
@ -75,7 +75,7 @@ from wcs.conditions import Condition, ValidationError
|
|||
from qommon import _, ngettext
|
||||
import misc
|
||||
from .humantime import humanduration2seconds, seconds2humanduration, timewords
|
||||
from .misc import strftime, C_, HAS_GM
|
||||
from .misc import strftime, C_, HAS_PDFTOPPM
|
||||
from publisher import get_cfg
|
||||
from .template_utils import render_block_to_string
|
||||
|
||||
|
@ -707,7 +707,7 @@ class FileWithPreviewWidget(CompositeWidget):
|
|||
return False
|
||||
|
||||
if filetype == 'application/pdf':
|
||||
return HAS_GM
|
||||
return HAS_PDFTOPPM
|
||||
|
||||
if not filetype.startswith('image/'):
|
||||
return False
|
||||
|
|
|
@ -54,10 +54,10 @@ from qommon.template import Template
|
|||
from django.utils.six import StringIO
|
||||
|
||||
try:
|
||||
subprocess.check_call(['which', 'gm'], stdout=open('/dev/null', 'w'))
|
||||
HAS_GM = True
|
||||
subprocess.check_call(['which', 'pdftoppm'], stdout=open('/dev/null', 'w'))
|
||||
HAS_PDFTOPPM = True
|
||||
except subprocess.CalledProcessError:
|
||||
HAS_GM = False
|
||||
HAS_PDFTOPPM = False
|
||||
|
||||
|
||||
EXIF_ORIENTATION = 0x0112
|
||||
|
@ -570,7 +570,7 @@ def file_digest(content, chunk_size=100000):
|
|||
|
||||
def can_thumbnail(content_type):
|
||||
if content_type == 'application/pdf':
|
||||
return bool(HAS_GM and Image)
|
||||
return bool(HAS_PDFTOPPM and Image)
|
||||
if content_type and content_type.startswith('image/'):
|
||||
return bool(Image is not None)
|
||||
return False
|
||||
|
@ -583,7 +583,7 @@ def get_thumbnail(filepath, content_type=None):
|
|||
if content_type == 'application/pdf':
|
||||
try:
|
||||
fp = StringIO(subprocess.check_output(
|
||||
['gm', 'convert', '-geometry', '500x', 'pdf:%s' % filepath, 'png:-']))
|
||||
['pdftoppm', '-png', '-scale-to-x', '500', '-scale-to-y', '-1', filepath]))
|
||||
except subprocess.CalledProcessError:
|
||||
raise ThumbnailError()
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue