Catching a Cropped Logo in Link Previews Twice, Before and After the OGP Image Is Exported
I sent the URL of a site I had built to a chat, and the link card cut off the last letter of the logo. Two things caused it: the source image was exported broken, and the card crops the left and right edges. Here is the placement check I put in the generator, a check that counts pixels in the exported file, a fetch from the crawler's side, and what to do when an old preview refuses to go away.
It was the week I launched a site I had built for an artist client. To check it, I sent the URL to a chat with only myself in it. The card appeared. But on the right side of the image, the logo stopped halfway through its last letter.
My first thought was that LINE was doing something to it, shrinking the image to fit the card. When I opened public/ogp.png at full size, I found I was only half right. In the 1200×630 source image itself, the logo had already run off the right edge of the canvas.
As an indie developer building and running my own sites, I tend to launch with a "temporary" OGP image still in place. I had never once looked at that placeholder's output at full size. What follows is the two causes I found and the shape my checks have taken since.
The short version
A cropped OGP image comes from two things at once: the exported file is broken, and the card crops the sides. Fix only one and the other still cuts the logo.
At export: the generator measures the text and logo it places, and refuses to save if anything leaves the center square.
After export: count the pixels in the finished JPEG and find where anything other than the background appears. This catches glows and soft edges the generator never measured.
From the sharing side: fetch the page and image with crawler User-Agents and confirm a 200 with no redirects.
Even after all three pass, an old card can linger in a chat. What I changed then was not the image URL but the page URL. The reason is further down.
What actually happened
There were two causes.
The first was the source image. When I made the placeholder, I placed the logo by a fixed coordinate from the top left without measuring its width. When the font changed, the text got wider and the last letter slid off the canvas. The script raised no error. It wrote the broken image without complaint.
The second was how the card displays it. A chat link card does not necessarily show a 1200×630 (1.91:1) image at its own ratio; it crops the left and right to fit the card. It is safest to assume X, Facebook, Slack, and Discord each crop to their own ratios. I have only confirmed this on LINE on a real device, and I have not verified the other services' ratios.
So even with the source fixed, a design that pushes the logo to the right would still be cut by the card. It took me a while to see these as two separate problems.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦Before you swap an OGP image, you can tell from a script's output alone whether the logo or name sits where a share card will crop it
✦Every export now produces a center square and a 300px-wide thumbnail, so you can check in under a minute whether the name is readable in a chat
✦When an old preview will not go away, you will know whether to change the image URL or the page URL
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
After some back and forth, I standardized OGP images like this:
1200×630, JPEG, under 1MB. The same image was 306KB as PNG and 82KB as JPEG. I avoid WebP because I am not confident chat cards handle it.
Required elements (logo, name, title) stay inside the central 630×630 square.
10% on every side (120px horizontally, 63px vertically) is the target margin.
The whole canvas is filled with the background color, so cropped edges never show white.
In a phone chat, the card shrinks to roughly 300px wide. I check that the name is readable at that size.
Writing the rules down does not guarantee they will be followed the next time the image changes. In my experience, the person who wrote them is the first to forget. So I moved the weight onto checks that stop the build when the rules are broken.
Stage 1: a placement check inside the generator
In the Pillow script that assembles the OGP image, I check placement right before saving. Text is measured with textbbox and centered by its real size. Not choosing coordinates by hand turned out to be the best prevention.
#!/usr/bin/env python3"""Assemble the OGP image and check the safe zone before saving."""from PIL import Image, ImageDraw, ImageFontW, H = 1200, 630SAFE = ((W - H) // 2, int(H * 0.10), (W + H) // 2, H - int(H * 0.10))BG = (10, 10, 10) # fill everything so cropped edges never go whitedef inside(box, area): l, t, r, b = box L, T, R, B = area return L <= l and T <= t and r <= R and b <= Bdef build(title, subtitle, font_path=None): img = Image.new("RGB", (W, H), BG) d = ImageDraw.Draw(img) big = ImageFont.truetype(font_path, 72) if font_path else ImageFont.load_default(size=72) small = ImageFont.truetype(font_path, 30) if font_path else ImageFont.load_default(size=30) placed = [] y = H // 2 - 60 for text, font, color in [(title, big, (240, 236, 228)), (subtitle, small, (170, 164, 156))]: l, t, r, b = d.textbbox((0, 0), text, font=font) x = (W - (r - l)) // 2 - l # center by the text's real size d.text((x, y), text, font=font, fill=color) placed.append((text, (x + l, y + t, x + r, y + b))) y += (b - t) + 36 # stop before writing; assert disappears under python -O, so do not rely on it bad = [(text, box) for text, box in placed if not inside(box, SAFE)] if bad: raise SystemExit("\n".join(f"outside safe zone: '{t}' {b} / safe={SAFE}" for t, b in bad)) return imgif __name__ == "__main__": import sys title = sys.argv[1] if len(sys.argv) > 1 else "STUDIO NAME" img = build(title, "Works & Notes") img.save("ogp-v4.jpg", "JPEG", quality=85, optimize=True, progressive=True) print("saved ogp-v4.jpg")
Pass a long name and it stops without saving. This is the output with Pillow 12.3.0 on my machine:
$ python3 -O make_ogp.py "A VERY LONG STUDIO NAME HERE"outside safe zone: 'A VERY LONG STUDIO NAME HERE' (31, 274, 1169, 326) / safe=(285, 63, 915, 567)$ echo $?1
There is a reason it uses SystemExit instead of assert. The script I actually run in production uses assert, but under python3 -O every assert line is skipped. I would rather not have the check vanish quietly on the day someone adds the optimize flag to the build.
Stage 2: count the pixels in the exported file
The stage 1 check only sees what the script itself measured. That is where the trap was.
Today I re-ran the following check against the OGP image actually in production (an artwork photo in the center, the name below it). The generator's own check passed when it was exported; the script is built so that it cannot write the file otherwise.
#!/usr/bin/env python3"""After export, check an OGP image for cropped edges and the safe zone.usage: python3 ogp_check.py public/ogp-v4.jpg [--out _ogp_preview]"""import argparse, os, sysfrom PIL import Image, ImageChopsW, H = 1200, 630MARGIN_Y = int(H * 0.10) # 63px top/bottom is a target marginSAFE = ((W - H) // 2, 0, (W + H) // 2, H) # central 630x630MAX_BYTES = 1_000_000TOL = 24 # distance from the background; high enough to ignore JPEG noisedef ink_mask(img, bg): """Return a mask with 255 wherever a pixel is more than TOL from the background""" diff = ImageChops.difference(img, Image.new("RGB", img.size, bg)) r, g, b = diff.split() far = ImageChops.lighter(ImageChops.lighter(r, g), b) # max of the three channels return far.point(lambda v: 255 if v > TOL else 0)def main(): ap = argparse.ArgumentParser() ap.add_argument("path") ap.add_argument("--out", default="_ogp_preview") a = ap.parse_args() errors = [] size = os.path.getsize(a.path) img = Image.open(a.path) if img.size != (W, H): errors.append(f"size is {img.size} (expected {W}x{H})") if img.format != "JPEG": errors.append(f"format is {img.format} (JPEG recommended)") if size > MAX_BYTES: errors.append(f"{size:,} bytes (keep under 1MB)") rgb = img.convert("RGB") bg = rgb.getpixel((2, 2)) # treat the top-left corner as the background for corner in [(W - 3, 2), (2, H - 3), (W - 3, H - 3)]: c = rgb.getpixel(corner) if max(abs(x - y) for x, y in zip(c, bg)) > TOL: errors.append(f"corners differ {corner}={c} (fill the whole canvas)") box = ink_mask(rgb, bg).getbbox() # where anything but the background appears warnings = [] if box is None: errors.append("nothing other than the background was found") else: l, t, r, b = box print(f"content box: x={l}..{r} y={t}..{b}") # left/right is what gets cropped -> error; top/bottom is a target -> warning if l < SAFE[0] or r > SAFE[2]: errors.append(f"content outside the central 630x630 (will be cut when cropped) {box}") if t < MARGIN_Y or b > H - MARGIN_Y: warnings.append(f"{max(MARGIN_Y - t, b - (H - MARGIN_Y), 0)}px into the 10% top/bottom margin {box}") # for eyes: the center square, and a ~300px-wide thumbnail like a chat card os.makedirs(a.out, exist_ok=True) rgb.crop(SAFE).save(os.path.join(a.out, "center_square.png")) rgb.resize((300, round(300 * H / W)), Image.LANCZOS).save(os.path.join(a.out, "card_300px.png")) for w in warnings: print("WARN:", w) for e in errors: print("NG:", e) print("OK" if not errors else f"{len(errors)} issue(s)") sys.exit(1 if errors else 0)if __name__ == "__main__": main()
Here is the result on the production image:
$ python3 ogp_check.py public/ogp-v3.jpgcontent box: x=427..772 y=54..569WARN: 9px into the 10% top/bottom margin (427, 54, 772, 569)OK
Horizontally the content spans 427 to 772, comfortably inside the center square (285 to 915). No risk of the card cutting it. But the top edge sits at 54px and the bottom at 569px, both inside the 10% target (63px and 567px).
Reading the generator again, I found two reasons.
It draws a slightly larger glow behind the artwork. The check only measured the artwork's diameter; the glow's spread was never counted. In pixels, that glow reached into the top margin.
The vertical margin check was written as 40px, not the 63px (10%) in the rules document. After writing the rules, I had never brought the script's numbers back in line.
The generator's check measures the shape I meant to place; the post-export check measures the pixels that actually landed. Either one alone misses the other's drift — in this case, only adding stage 2 showed me that the rules and the script disagreed.
To my mind, these 9px do not need fixing. Cards crop the sides, and the vertical margin is a visual target. So I split the check instead: anything outside the center square horizontally is an error (exit code 1), and the vertical margin is a warning that still passes. I have not replaced the production image for now.
This check assumes a design with a solid background filling the canvas. When I ran it on another site whose OGP image is a full-bleed photo, the background itself counted as content and the whole thing failed. For designs like that, I would drop the corner and pixel-range checks and keep only a visual look at center_square.png and card_300px.png.
Stage 3: fetch it from the crawler's side
Even with a correct image, cards sometimes fail to appear or stay stale. The first suspect is the site itself, so I check how my site looks to the sharing services' crawlers.
#!/usr/bin/env bash# Check OGP from the sharing side: tag position, image response, per-UA differences# usage: bash og_fetch_check.sh https://example.com/set -uURL="$1"HTML="$(mktemp)"; trap 'rm -f "$HTML"' EXITcurl -sL -m 20 "$URL" -o "$HTML" || { echo "NG: could not fetch the page"; exit 1; }# byte offset of og:image inside the headOFF=$(grep -bo 'property="og:image"' "$HTML" | head -1 | cut -d: -f1)HEAD_END=$(grep -bo '</head>' "$HTML" | head -1 | cut -d: -f1)echo "og:image tag at byte ${OFF:-none} / </head> at byte ${HEAD_END:-none}"[ -z "${OFF:-}" ] && { echo "NG: og:image not found"; exit 1; }IMG=$(grep -o '<meta[^>]*property="og:image"[^>]*>' "$HTML" | head -1 | sed -E 's/.*content="([^"]+)".*/\1/')case "$IMG" in http*) ;; *) echo "NG: og:image is not an absolute URL: $IMG"; exit 1;; esacecho "image: $IMG"FAIL=0for UA in "facebookexternalhit/1.1" "Twitterbot/1.0" "Slackbot-LinkExpanding 1.0" "Mozilla/5.0"; do R=$(curl -s -m 20 -A "$UA" -o /dev/null -w '%{http_code} %{content_type} %{size_download} %{num_redirects}' "$IMG") echo " [$UA] status/type/bytes/redirects = $R" set -- $R [ "$1" = "200" ] || FAIL=1 [ "$4" = "0" ] || echo " note: redirect present (some crawlers will not follow it)"doneexit $FAIL
I print the tag position because some crawlers are said to read only the first part of a long head. I have not been able to confirm a published byte limit for any service, so I simply treat earlier as better and keep the og tags near the top of the head.
The script only catches tags where property comes before content. If your site writes them the other way round, adjust the grep pattern. If results differ by User-Agent, a bot-protection layer such as Cloudflare's may be blocking the crawler. Whenever a chat card fails to show, I confirm the 200 and the image type in this output before looking anywhere else.
When an old card will not go away: change the page URL
This was the part that ran most against my intuition.
Even with everything on the site side verified, a chat card can keep showing an old image, sometimes the placeholder from before launch. LINE caches link previews per URL for a long time, and I could find no public way to purge them. If you shared the URL even once in the placeholder days, that result stays.
There are two fixes, and they do different jobs:
When replacing the image: put a version number in the file name (/ogp-v3.jpg → /ogp-v4.jpg). I do not use a query like /ogp.jpg?v=4, because there are reports that some crawlers drop image URLs with queries. I have not reproduced that myself; I am leaning to the safe side based on the reports. Keep the old file, since existing caches may still request it.
When sharing a page whose card is stale: add a query to the page URL (https://example.com/?v=2). LINE treats it as a different URL and fetches again. With a correct canonical, search is unaffected.
No query on the image URL, a query on the page URL. They look like opposite decisions, but one is so the crawler reliably comes to fetch, the other so it skips the cache and fetches again. The goal is the same.
With the Next.js App Router, I keep the reference in one place in the metadata:
// app/layout.tsx (or a shared SEO config)import type { Metadata } from "next";const OGP = "/ogp-v4.jpg"; // bump the number on every swap; keep old files in public/export const metadata: Metadata = { metadataBase: new URL("https://example.com"), openGraph: { images: [{ url: OGP, width: 1200, height: 630, alt: "Studio Name" }], }, twitter: { card: "summary_large_image", images: [OGP], },};
Review width and height whenever the image changes. Leaving old dimensions on an image with a new ratio can throw off how the card is laid out. Setting metadataBase makes relative image paths come out as absolute URLs. When the stage 3 script stops with "not an absolute URL," this is usually what was missing.
The order I follow on every swap
Export with the generator (confirm stage 1 does not stop it).
Run ogp_check.py; confirm zero errors and read the warnings.
Open _ogp_preview/card_300px.png at full size and check by eye that the name is readable.
Bump the file name's version number and update the metadata reference and width/height.
After deploying, run og_fetch_check.sh and confirm 200 with zero redirects for every User-Agent.
Send the URL to a chat with only myself and look at the card on a real device. If it is stale, resend the page URL with ?v=N.
For X and Facebook, refresh the cache in each service's debugger before checking.
What I hand to Antigravity's agent
An agent can write stage 1 and stage 2 scripts that work well enough. But if I leave the safe-zone numbers to its judgment, it could easily retrace my own mistake of rules and script drifting apart. When I ask, I decide the numbers and how I want the output shown before handing it over.
Write a generator at scripts/gen_ogp.py that produces public/ogp-v4.jpg.- Canvas 1200x630, fill the whole background with #0A0A0A- Measure the name and subtitle with textbbox, center them, and keep them inside the central 630x630 and 63px from top and bottom- If anything is outside, stop with SystemExit and do not save the image (do not use assert)- After export, run python3 scripts/ogp_check.py public/ogp-v4.jpg and paste the full output uneditedDo not judge whether card_300px.png looks good. I will open it and decide.
The last line is how I keep the looking for myself. A machine counts pixel ranges more accurately than I do, but whether a name is readable on a card shrunk to 300px is something I open and decide.
Where people tend to trip
Images where the corners are not the background: with a pattern or gradient in the corners, the check mistakes the background. Hard-code bg in that case.
Setting TOL too low: JPEG compression noise gets counted as content and the box expands to the whole canvas. On my images, 24 was stable. How much of a glow counts as content also depends on this value (on the production image, raising it to 90 brought the top edge to exactly 63px).
Deleting the old file after a swap: existing caches request it and get a 404. Keep it in public/.
Checking against your own device's cache: a card you have opened once stays cached on the device too. Check in a fresh chat or one with only yourself.
Where I draw the line
Scripts stop the cropping; my own eyes decide whether it reads. From the day I wrote the rules down, I have left the enforcing to the checks and kept only that last look for myself.
A good first step is to run ogp_check.py once against your current OGP image and see whether the content box fits inside the center square. Like me, you may find your rules and your script quietly disagree.
Antigravity Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.