Skip to content

Commit de946e3

Browse files
committed
App: thumbnail nits
[skip ci]
1 parent ec5040d commit de946e3

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎scripts/gdrive_app.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,20 @@ def update_visible_thumbnails(self):
415415
self.thumbnail_pool.start(worker)
416416

417417
def on_thumbnail_loaded(self, file_id: str, img: QImage):
418+
# Ensure the image is padded to the full icon size to prevent label shifting
419+
# and ensure the previous render is fully cleared.
420+
target_size = self.file_view.iconSize().width()
421+
if not img.isNull() and (img.width() != target_size or img.height() != target_size):
422+
padded = QImage(target_size, target_size, QImage.Format_ARGB32)
423+
padded.fill(Qt.transparent)
424+
painter = QPainter(padded)
425+
# Center the image
426+
x = (target_size - img.width()) // 2
427+
y = (target_size - img.height()) // 2
428+
painter.drawImage(x, y, img)
429+
painter.end()
430+
img = padded
431+
418432
pixmap = QPixmap.fromImage(img)
419433
self.thumbnail_cache.put(file_id, pixmap)
420434
if file_id in self.item_mapping:

‎scripts/videoutils.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ def render_video_thumbnail(video_path: Path, size=128) -> bytes:
77
"""Uses ffmpeg to extract a frame from a video file."""
88
try:
99
# We try to get a frame at 1 second in.
10-
# -ss 1: seek to 1 second
10+
# -ss 5: seek to 5 seconds
1111
# -i: input file
12+
# -vf scale: resize maintaining aspect ratio
1213
# -vframes 1: extract 1 frame
1314
# -f image2pipe: output as image pipe
1415
# -vcodec png: encode as png
15-
# -vf scale: resize maintaining aspect ratio
1616
cmd = [
1717
'ffmpeg',
18-
'-ss', '1',
18+
'-ss', '5',
1919
'-i', str(video_path),
20+
'-vf', f'thumbnail,scale={size}:-1',
2021
'-vframes', '1',
2122
'-f', 'image2pipe',
2223
'-vcodec', 'png',
23-
'-vf', f'scale={size}:-1',
2424
'-'
2525
]
2626
# We use a short timeout and capture output

0 commit comments

Comments
 (0)