Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Logs the errors during thumbnail generation, updates default to be WebP

Trenton H1a87c730bc91
diff --git a/src/documents/parsers.py b/src/documents/parsers.py
index 2e6b17cb5..dc67af1a2 100644
--- a/src/documents/parsers.py
+++ b/src/documents/parsers.py
@@ -166,11 +166,11 @@ def run_convert(
raise ParseError(f"Convert failed at {args}")
-def get_default_thumbnail() -> str:
+def get_default_thumbnail() -> Path:
"""
Returns the path to a generic thumbnail
"""
- return os.path.join(os.path.dirname(__file__), "resources", "document.png")
+ return (Path(__file__).parent / "resources" / "document.webp").resolve()
def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -> str:
@@ -183,12 +183,13 @@ def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -
"to ghostscript. Check your /etc/ImageMagick-x/policy.xml!",
extra={"group": logging_group},
)
+ # Ghostscript doesn't handle WebP outputs
gs_out_path = os.path.join(temp_dir, "gs_out.png")
cmd = [settings.GS_BINARY, "-q", "-sDEVICE=pngalpha", "-o", gs_out_path, in_path]
try:
if not subprocess.Popen(cmd).wait() == 0:
raise ParseError(f"Thumbnail (gs) failed at {cmd}")
- # then run convert on the output from gs
+ # then run convert on the output from gs to make WebP
run_convert(
density=300,
scale="500x5000>",
@@ -203,11 +204,12 @@ def make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group=None) -
return out_path
- except ParseError:
+ except ParseError as e:
+ logger.error(f"Unable to make thumbnail with Ghostscript: {e}")
# The caller might expect a generated thumbnail that can be moved,
# so we need to copy it before it gets moved.
# https://github.com/paperless-ngx/paperless-ngx/issues/3631
- default_thumbnail_path = os.path.join(temp_dir, "document.png")
+ default_thumbnail_path = os.path.join(temp_dir, "document.webp")
copy_file_with_basic_stats(get_default_thumbnail(), default_thumbnail_path)
return default_thumbnail_path
@@ -231,7 +233,8 @@ def make_thumbnail_from_pdf(in_path, temp_dir, logging_group=None) -> str:
output_file=out_path,
logging_group=logging_group,
)
- except ParseError:
+ except ParseError as e:
+ logger.error(f"Unable to make thumbnail with convert: {e}")
out_path = make_thumbnail_from_pdf_gs_fallback(in_path, temp_dir, logging_group)
return out_path
diff --git a/src/documents/resources/document.png b/src/documents/resources/document.png
deleted file mode 100644
index 164afd14d..000000000
Binary files a/src/documents/resources/document.png and /dev/null differ
diff --git a/src/documents/resources/document.webp b/src/documents/resources/document.webp
new file mode 100644
index 000000000..700dd79e2
Binary files /dev/null and b/src/documents/resources/document.webp differ
diff --git a/src/documents/tests/test_file_handling.py b/src/documents/tests/test_file_handling.py
index 9e27b9aad..89c2e6e46 100644
--- a/src/documents/tests/test_file_handling.py
+++ b/src/documents/tests/test_file_handling.py
@@ -820,7 +820,7 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
@override_settings(FILENAME_FORMAT="{title}")
def test_archive_deleted2(self):
- original = os.path.join(settings.ORIGINALS_DIR, "document.png")
+ original = os.path.join(settings.ORIGINALS_DIR, "document.webp")
original2 = os.path.join(settings.ORIGINALS_DIR, "0000001.pdf")
archive = os.path.join(settings.ARCHIVE_DIR, "0000001.pdf")
Path(original).touch()
@@ -828,9 +828,9 @@ class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, Test
Path(archive).touch()
doc1 = Document.objects.create(
- mime_type="image/png",
+ mime_type="image/webp",
title="document",
- filename="document.png",
+ filename="document.webp",
checksum="A",
archive_checksum="B",
archive_filename="0000001.pdf",