thumbnail: Avoid BytesIO.getbuffer.

It seems to cause ‘BufferError: Existing exports of data: object
cannot be re-sized’ on Python 3.13.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2025-08-12 16:38:18 -07:00
committed by Tim Abbott
parent f9faad0997
commit 2ddafe728e

View File

@@ -59,8 +59,9 @@ def ensure_thumbnails(image_attachment: ImageAttachment) -> int:
return 0 return 0
written_images = 0 written_images = 0
image_bytes = BytesIO() with BytesIO() as f:
save_attachment_contents(image_attachment.path_id, image_bytes) save_attachment_contents(image_attachment.path_id, f)
image_bytes = f.getvalue()
try: try:
# TODO: We could save some computational time by using the same # TODO: We could save some computational time by using the same
# bytes if multiple resolutions are larger than the source # bytes if multiple resolutions are larger than the source
@@ -96,7 +97,7 @@ def ensure_thumbnails(image_attachment: ImageAttachment) -> int:
else: else:
load_opts = "n=1" load_opts = "n=1"
resized = pyvips.Image.thumbnail_buffer( resized = pyvips.Image.thumbnail_buffer(
image_bytes.getbuffer(), image_bytes,
thumbnail_format.max_width, thumbnail_format.max_width,
height=thumbnail_format.max_height, height=thumbnail_format.max_height,
option_string=load_opts, option_string=load_opts,