Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your link previews are blank because og:image is missing. Here is a stdlib-only Python fix

When you paste a link to your product, docs page or side project into Slack, Discord, X or LinkedIn, the platform builds a preview card from your page's Open Graph tags. If og:image is missing or points at a generic platform default, the preview is a grey box or a stock logo. That hurts clicks, and you usually don't notice because you never see your own link the way other people do. This post…

When you link your product, documentation or personal project to Slack, Discord, X or LinkedIn, the platform generates a preview card using your Open Graph tags. If the og:image tag is absent or points to a default image, the preview appears as a grey box or stock logo. This can negatively impact click-through rates, as users cannot see your actual content.

This article outlines three ways to address this issue: a quick check for missing og:image, an all-standard-library Python script to generate a 1280x720 cover image, and how to integrate the image into your webpage.

To verify if your page has an og:image, run this command: curl -s https://your-site.example/page | grep -io meta[^ ]*og:image[^ ]. Three possible outcomes: no output, indicating the absence of an og:image; a generic URL, such as your host's or storefront's logo; or a unique image specific to your page. Additionally, you can check og:title and og:description in the same manner.

To create a PNG image using only the Python standard library, refer to the following code snippet:

```python

import struct

import zlib

def _chunk(kind, data):

body = kind + data

return (struct.pack(I, len(data)) + body + struct.pack(I, zlib.crc32(body) & 0xFFFFFFFF))

def write_png(path, width, height, rows):

raw = b'\x00' + b''.join(rows)

ihdr = struct.pack(IIBBBBB, width, height, 8, 2, 0, 0, 0)

png = b'\x89PNG\r\n\x1a\n' + _chunk(b'IHDR', ihdr) + _chunk(b'IDAT', zlib.compress(raw, 9)) + _chunk(b'IEND', b'')

with open(path, 'wb') as f:

f.write(png)

```

Use this script to create a diagonal two-color gradient with a solid accent bar, which looks far more engaging than a grey box. The gradient can be customized by adjusting the color values for the colors, c1 and c2, and accent.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

GDB 18.1 released

Version 18.1 of the GDB interactive debugger has been released. Changes include new commands to manipulate the environment of the subprocess, the ability to save the command history to a file, support…

A web shop without a database or payment provider: the ForgeCMS shop module

Today the shop module for ForgeCMS went live. Your customers can pay in two ways: in June (Ğ1) , a free currency, or in euros by plain bank transfer .

  • ForgeCMS shop module launched with no database or payment provider
  • Two payment options: Ğ1 libre currency and euros by bank transfer
  • Module costs one-time €39 license with no subscription fees

More from Saturday 26 September →