Why pack_product.py Renders Both a 1280x720 Cover and a 600x600 Thumbnail
Описание и применение
Одно изображение не достаточно: при квадратном разрезе отрезается подзаголовок, и магазин выглядит неполным. Скрипт pack_product.py теперь пишет два файла на продукт — 1280x720封面 и 600x600缩略图. Оба JPEG, имена <slug>-cover.jpg и <slug>-thumb.jpg. Источник читается один раз, дваwrites на диск. Квадратный кадр создаётся первым, чтобыcrop-решение делалось один раз.
Задача
A single-image render produces a cover that gets cropped by square containers, cutting off the subtitle and making the listing look unfinished next to competitors.
Результат
Two images per product: 1280x720 cover keeps title readable with subtitle visible, 600x600 thumbnail drops subtitle to avoid four-pixel noise when cropped by square containers. Same folder feeds Adobe 5-column, Vecteezy 4-column, or Dreamstime 15-column CSVs without manual renaming.
Рабочий процесс
- Read source art once.
- Resize to 600x600 with center cover crop, draw title, save thumbnail as
<slug>-thumb.jpg. - Build 1280x720 canvas in background color, paste composed square region at natural size, draw title and subtitle at wide-layout positions, save cover as
<slug>-cover.jpg. - Run gc.collect() after each product.
- Peak memory checked via resource.getrusage(RUSAGE_SELF).ru_maxrss.
Доказательства
First pack I shipped was a zip and a 1280x720 cover. Clean render, centered title, subtitle underneath. Storefront grid showed it as a square. The crop took the middle of the frame and cut the subtitle off at both edges.
If I render one image and let the platform crop it, I lose control of where the crop lands. Text near the edge is the first thing to go.
The square one drops the subtitle entirely, because a subtitle at 600x600 is four pixels tall and reads as noise.
Source read is one, disk writes are two.
I used to render a preview at the largest size I could, then downscale. That was wasted work. A preview is for eyeballing placement, and 60 dpi is enough for that.
39 finished products, 856 MB of output, and a stack of orphan cover files I could not match to anything. If the zip does not exist, the cover does not get made.
The cover step is the last thing that runs. Metadata first, because a wrong CSV header gets a batch rejected immediately and wasted renders do not help.
- Дата записи: 2026-11-02T00:43:57.035Z