How to Share Code as Images People Can Read
How many lines fit, which sizes to post, how to keep code readable on a phone, how to avoid leaking keys, and why the code belongs in the alt text — for X, LinkedIn, docs and slides.
Fastest way
Ask your AI to do it
Paste this into the AI agent you already use:
Help me use a Skill with another agent. Ask which agents and package I use, check supported locations and tools, identify any assumptions to change, and verify the workflow with a small example.
Quick answer
Show 5–20 lines that prove one point, at a size where the code is still about 8 px tall when a phone shows the image. Highlight the line that matters, mask anything secret, export at 2× or at the exact size of the post, and paste the code itself into the alt text.
Sizes to post
- Link previews and X: 1200 × 630.
- Square feed posts: 1080 × 1080; carousels and portrait posts: 1080 × 1350.
- Slides: 1920 × 1080; docs: a 2× PNG or an SVG at the width of the content column.
- LinkedIn shows carousels as document posts: upload the slides as one PDF.
Keep it readable on a phone
A fixed-size image shrinks to fit the feed, so long lines and many lines make the text tiny. Divide the feed width (about 360 px for a phone, 500 px for X on desktop) by the image width and multiply by the code's font size: aim for 7.5–8 px or more. Shorten the longest line, show fewer lines, or wrap lines in tall formats.
Never leak a key
Screenshots of config files and terminals are a common way API keys leak. Search the code for keys, tokens, connection strings with passwords and internal hostnames before capturing it, and mask them. Masking an image does not revoke a key that was ever shared: rotate it.
Put the code in the alt text
Screen readers and search engines cannot read code inside an image. Add the code itself, or a summary and a link, as the image description; X and many other sites allow about 1,000 characters. Offer the code as text in a reply or a gist too, so people can copy it.
Do it with an AI agent
CodeShot highlights 20 languages, masks secrets, renders link-preview, square, portrait and slide sizes and carousels with a PDF, checks the code size at feed width, and writes alt text with the code.