Skip to content

Use uploaded image dimensions in Markdown image nodes - #94

Open
MattFisher wants to merge 1 commit into
ma2za:mainfrom
MattFisher:fix/image-dimensions-from-upload
Open

MattFisher wants to merge 1 commit into
ma2za:mainfrom
MattFisher:fix/image-dimensions-from-upload

Conversation

@MattFisher

@MattFisher MattFisher commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Local images in Markdown are always recorded as 1456×819 with no byte size or content type, whatever the file really is. This PR takes those values from Substack's upload response instead.

The problem

nodes.captioned_image() hard-codes "width": 1456, "height": 819, "bytes": None, "type": None. Api.get_image() already returns the real values (imageWidth, imageHeight, bytes, contentType), but _captioned_image() in mdrender.py only keeps the url.

For example, a 1440×3576 PNG pushed with from_markdown() was stored as:

{"width": 1456, "height": 819, "bytes": null, "type": null}

With this change the same image is stored as:

{"width": 1440, "height": 3576, "bytes": 418331, "type": "image/png"}

The change

  • nodes.captioned_image() gains optional width, height, size_bytes and mime_type arguments. The defaults are the old values, so existing callers get the same node as before.
  • _captioned_image() passes the upload response's values through for local images.
  • Width and height are only used as a pair of positive integers. If either is missing or malformed, the node keeps the old 1456×819 placeholder.

Remote image URLs are untouched: nothing is uploaded for them, so their size is still unknown and they keep the placeholder.

Testing

  • New offline tests in test_local_markdown_images.py cover the happy path and the fallback for missing, partial, zero, string and boolean dimensions.
  • pytest -q -m "not live" --strict-markers: 298 passed.
  • Checked against a real draft: four local PNGs of different heights were pushed and read back with their true sizes, byte counts and image/png.

Note

#95 touches the lines next to this one in mdrender.py, so whichever of the two is merged second will need a small rebase. I'm happy to do that.

🤖 Generated with Claude Code

Local images in Markdown were always recorded as 1456x819 with no byte
size or content type, whatever the real file was. Substack's upload
response already reports imageWidth, imageHeight, bytes and contentType,
so carry those into the image2 node. Dimensions are only used as a
valid pair; otherwise the previous placeholder size is kept.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant