preview: remove ffprobe fallback and unused json import

_get_image_dimensions now relies solely on pyvips header reading.
If pyvips cannot read the header the function returns None and the
caller encodes at full resolution rather than falling back to ffprobe.
Remove unused stdlib json import.
This commit is contained in:
2026-05-01 22:51:58 +00:00
parent 13f32c57ab
commit 8b4e622aef
+2 -27
View File
@@ -2,7 +2,6 @@ import asyncio
import contextlib import contextlib
import gc import gc
import io import io
import json
import mimetypes import mimetypes
import struct import struct
import subprocess import subprocess
@@ -706,37 +705,13 @@ def _get_image_dimensions(path: Path) -> tuple[int, int] | None:
"""Probe image dimensions. """Probe image dimensions.
pyvips can read the header of most formats (including HEIC) without pyvips can read the header of most formats (including HEIC) without
fully decoding the image. ffprobe is used as a fallback. fully decoding the image.
""" """
try: try:
img = pyvips.Image.new_from_file(str(path)) img = pyvips.Image.new_from_file(str(path))
return img.width, img.height return img.width, img.height
except pyvips.error.Error: except pyvips.error.Error:
pass return None
try:
result = subprocess.run(
[
"ffprobe",
"-v",
"error",
"-select_streams",
"v:0",
"-show_entries",
"stream=width,height",
"-of",
"csv=s=x:p=0",
str(path),
],
capture_output=True,
text=True,
check=True,
)
parts = result.stdout.strip().split("x")
if len(parts) == 2:
return int(parts[0]), int(parts[1])
except Exception:
pass
return None
def _image_via_ffmpeg(path: Path, maxsize: int, quality: int) -> bytes: def _image_via_ffmpeg(path: Path, maxsize: int, quality: int) -> bytes: