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。一次读取源文件,两次写入磁盘。先合成方形图像,使裁剪决策只做出一次。
问题
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