Skip to content

Commit

Permalink
Suggest including aspectRatio in the posting guide (#290)
Browse files Browse the repository at this point in the history
* Suggest including aspectRatio in the posting guide

* indent

* Update posts.md

* Update posts.md

* Update posts.md
  • Loading branch information
gaearon authored Dec 7, 2024
1 parent 3c16809 commit 0032a8f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions docs/advanced-guides/posts.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,27 @@ The blob object, as JSON, would look something like:
}
```

The blob is then included in a `app.bsky.embed.images` array, along with an alt-text string. The `alt` field is required for each image. Pass an empty string if there is no alt text available.
The blob is then included in a `app.bsky.embed.images` array, along with an alt-text string and an aspect ratio.

To get the aspect ratio, you'll need a library like [Pillow](https://pillow.readthedocs.io/). Specifying the correct aspect ratio will help client apps display the images without performance or visual issues. The exact specific dimensions don't need to be known, only the ratio between the `width` and the `height` is important. If you don't know the image aspect ratio and don't parse the image to detect the dimensions, it is best to leave the `aspectRatio` field undefined instead of guessing.

```python
from PIL import Image

# ...

with Image.open(IMAGE_PATH) as im:
width, height = im.size

post["embed"] = {
"$type": "app.bsky.embed.images",
"images": [{
"alt": IMAGE_ALT_TEXT,
"image": blob,
"aspectRatio": {
"width": width,
"height": height
}
}],
}
```
Expand All @@ -395,6 +408,10 @@ A complete post record, containing two images, would look something like:
},
"mimeType": "image/webp",
"size": 760898
},
"aspectRatio": {
"width": 1280,
"height": 760
}
},
{
Expand All @@ -406,14 +423,18 @@ A complete post record, containing two images, would look something like:
},
"mimeType": "image/png",
"size": 13208
},
"aspectRatio": {
"width": 500,
"height": 300
}
}
]
}
}
```

Each post contains up to four images, and each image can have its own alt text and is limited to 1,000,000 bytes in size. Image files are *referenced* by posts, but are not actually *included* in the post (eg, using `bytes` with base64 encoding). The image files are first uploaded as "blobs" using `com.atproto.repo.uploadBlob`, which returns a `blob` metadata object, which is then embedded in the post record itself.
Each post contains up to four images, and each image can have its own alt text and aspect ratio. Individual images are limited to 1,000,000 bytes in size. Image files are *referenced* by posts, but are not actually *included* in the post (eg, using `bytes` with base64 encoding). The image files are first uploaded as "blobs" using `com.atproto.repo.uploadBlob`, which returns a `blob` metadata object, which is then embedded in the post record itself.

It's strongly recommended best practice to strip image metadata before uploading. The server (PDS) may be more strict about blocking upload of such metadata by default in the future, but it is currently the responsibility of clients (and apps) to sanitize files before upload today.

Expand Down

0 comments on commit 0032a8f

Please sign in to comment.