How to turn an AI image into an og:image link preview in Python
Ideogram 4.5 on Sume makes a 2:1 image at 1K as 1440x720. A Pillow crop to your link-preview size, plus the og:image:alt tag Open Graph asks for.

Crop it, then resize it, and write the alt tag. A 2:1 image from Ideogram 4.5 on Sume does not match every link-preview template, so cut it to the ratio your template wants instead of stretching it. The code below does that with Pillow, and the tag block at the end covers the alt text.
The target size is yours to set. This post does not state any platform's preview size, because the platform's own help page is the source for that.
The sizes you start from
| Aspect ratio | Size at 1K | Note |
|---|---|---|
| 1:1 | 1024 (2048 at 2K) | Square |
| 2:1 | 1440x720 | Edit override is 1408x704 |
| 3:1 / 1:3 | 3072x1024 / 1024x3072 | One size only |
No aspect_ratio on an edit | Same geometry as the source | Pass the ratio only when you want it to change |
Center-crop and resize
For a 1440x720 source and a 1200x630 target the crop keeps the full height and trims the sides. The function computes the crop box from the target ratio, so it also works for other sizes.
import sys
from PIL import Image
def og(src: str, dst: str, w: int = 1200, h: int = 630) -> None:
im = Image.open(src).convert("RGB")
cw = min(im.width, round(im.height * w / h))
ch = min(im.height, round(im.width * h / w))
left = (im.width - cw) // 2
top = (im.height - ch) // 2
box = (left, top, left + cw, top + ch)
im.crop(box).resize((w, h), Image.LANCZOS).save(dst)
print(f"crop {cw}x{ch} -> {w}x{h}")
if __name__ == "__main__":
if len(sys.argv) != 3:
raise SystemExit("usage: og.py SRC DST")
og(sys.argv[1], sys.argv[2])Compose before you crop
Center-cropping a 2:1 image to the template ratio removes the outer strip on each side, so keep the headline and the logo inside the middle of the frame. If you are generating the image, say so in the prompt: place the text in the central area with space to spare on both sides.
Check the crop by eye. A script cannot see that it cut a word in half.
The tag that goes with it
The Open Graph protocol page (read 2026-10-06) says og:image:alt should be specified if og:image is. Write what the image shows, and include any words printed on it.
<meta property="og:image" content="https://example.com/previews/launch.jpg">
<meta property="og:image:alt" content="Teal poster with the words Launch day in bold white type">Sources
Related posts
More in Media tools
- Can a YouTube Short be square? Rendering 1080x1080 in Sume Timeline
YouTube says Shorts can be square or vertical. How to export 1080x1080 from Sume Timeline, what fit does to a 9:16 source, and the 3-minute ceiling.
- Can a YouTube Shorts episode run 4 minutes? Split with source_in
No: the Shorts series limit is 180 seconds. Split a long cut into two parts with Sume Timeline audio.source_in and video source_in, one render per part.
- Can a YouTube Shorts series episode be square? Render 1080x1080
Yes. YouTube's Shorts series rule says portrait or square, up to 180 seconds. How to render a square episode with Sume Timeline output width, height and fit.
- Check a Short has sound and picture before adding it to a YouTube show
YouTube asks shows for high-quality video and sound and says no-visuals videos likely will not count. Probe each Short with Sume video inspect first.
Written by Sume