detect missing webp support

This commit is contained in:
ed 2021-05-28 05:00:08 +02:00
parent 374ff3433e
commit 96223fda01
4 changed files with 19 additions and 7 deletions

View file

@ -14,7 +14,7 @@ from .util import mp
from .authsrv import AuthSrv
from .tcpsrv import TcpSrv
from .up2k import Up2k
from .th_srv import ThumbSrv, HAVE_PIL
from .th_srv import ThumbSrv, HAVE_PIL, HAVE_WEBP
class SvcHub(object):
@ -47,6 +47,11 @@ class SvcHub(object):
self.thumbsrv = None
if not args.no_thumb:
if HAVE_PIL:
if not HAVE_WEBP:
args.th_no_webp = True
msg = "setting --th-no-webp because either libwebp is not available or your Pillow is too old"
self.log("thumb", msg, c=3)
self.thumbsrv = ThumbSrv(self, auth.vfs.all_vols)
else:
msg = "need Pillow to create thumbnails; for example:\n {} -m pip install --user Pillow"

View file

@ -21,12 +21,12 @@ class ThumbCli(object):
if self.args.no_vthumb and ext in FMT_FF:
return None
if fmt == "w" and self.args.th_no_webp:
fmt = "j"
if fmt == "j" and self.args.th_no_jpg:
fmt = "w"
if fmt == "w" and self.args.th_no_webp:
fmt = "j"
tpath = thumb_path(ptop, rem, mtime, fmt)
ret = None
try:

View file

@ -8,14 +8,13 @@ import threading
import subprocess as sp
from .__init__ import PY2
from .util import fsenc, Queue, Cooldown
from .util import fsenc, Queue, Cooldown, BytesIO
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe
if not PY2:
unicode = str
try:
HAVE_PIL = True
from PIL import Image, ImageOps
@ -27,6 +26,12 @@ try:
register_heif_opener()
except:
HAVE_HEIF = False
try:
Image.new("RGB", (2, 2)).save(BytesIO(), format="webp")
HAVE_WEBP = True
except:
HAVE_WEBP = False
except:
HAVE_PIL = False
@ -339,7 +344,7 @@ class ThumbSrv(object):
# thumb file
try:
b64, ts, ext = f.split(".")
if len(b64) != 24 or len(ts) != 8 or ext != "jpg":
if len(b64) != 24 or len(ts) != 8 or ext not in ["jpg", "webp"]:
raise Exception()
ts = int(ts, 16)

View file

@ -34,10 +34,12 @@ if not PY2:
from urllib.parse import unquote_to_bytes as unquote
from urllib.parse import quote_from_bytes as quote
from queue import Queue
from io import BytesIO
else:
from urllib import unquote # pylint: disable=no-name-in-module
from urllib import quote # pylint: disable=no-name-in-module
from Queue import Queue # pylint: disable=import-error,no-name-in-module
from StringIO import StringIO as BytesIO
surrogateescape.register_surrogateescape()
FS_ENCODING = sys.getfilesystemencoding()