Skip to content

Commit c4c3c86

Browse files
committed
docs: Image sizing guide
1 parent 12e08b0 commit c4c3c86

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed
229 KB
Loading
336 KB
Loading
245 KB
Loading

docusaurus/docs/Angular/components/AttachmentListComponent.mdx

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import AttachmentsScreenshot from "../assets/attachments-screenshot.png";
2+
import ImageSizingScreenshot1 from "../assets/image-sizing-screenshot-1.png";
3+
import ImageSizingScreenshot2 from "../assets/image-sizing-screenshot-2.png";
4+
import ImageSizingScreenshot3 from "../assets/image-sizing-screenshot-3.png";
25

3-
The `AttachmentList` compontent displays the attachments of a message. The following attachments are supported:
6+
The `AttachmentList` component displays the attachments of a message. The following attachments are supported:
47

58
- Images (including GIFs) are displayed inline
69
- Videos are displayed inline
@@ -40,5 +43,53 @@ You can use the [`AttachmentConfigurationService`](../services/AttachmentConfigu
4043

4144
You can provide your own attachment list component by the [`CustomTemplatesService`](../services/CustomTemplatesService.mdx)
4245

46+
### Image and video sizing
47+
48+
The following section details how the width and height of images and videos uploaded from files are computed.
49+
50+
#### Maximum size
51+
52+
You can control the maximum size of images and videos with the [`--str-chat__attachment-max-width`](../theming/component-variables.mdx) CSS variable (available only in [theme-v2](../theming/introduction.mdx)). The value of this variable must be a value that can be computed to a valid pixel value using the [`getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) method (for example: `300px`, `10rem`, `calc(300px - var(--margin))`, but not `100%`). If you provide an invalid value, the image and video sizing can break, which can lead to scrolling issues inside the message list (for example the message list isn't scrolled to the bottom when you open a channel).
53+
54+
:::tip
55+
If you're unsure about the value you provided for `--str-chat__attachment-max-width`, send an image/video to a channel, then inspect the `img`/`video` element inside the message list using your browser's development tools. Inside the **computed** properties of the element, you should see that `max-height` and `max-width` are set to a valid pixel value.
56+
:::
57+
58+
#### File size optimization
59+
60+
Based on the CSS settings provided for images and videos, the SDK will load an image (or thumbnail image in case of a video file) with a reduced file size while still providing sufficient image quality for the given dimensions. This will result in less network traffic and faster image load for users.
61+
62+
#### Aspect ratio
63+
64+
The SDK will try to display images and videos with their original aspect ratio, however this isn't always guaranteed. Three notable exceptions are:
65+
66+
1. if a message contains multiple lines of texts and/or multiple attachments, the image/video might be stretched to its `max-width`
67+
68+
**Example 1** - message with one line of text
69+
70+
<img src={ImageSizingScreenshot1} width="200" />
71+
72+
**Example 2** - message with multiple lines of text
73+
74+
<img src={ImageSizingScreenshot2} width="200" />
75+
76+
2. in Safari, images/videos with portrait orientation are stretched to `max-width`
77+
78+
**Example 3** - portrait images in Safari
79+
80+
<img src={ImageSizingScreenshot3} width="200" />
81+
82+
3. if the image/video can't be rendered with the original aspect ratio given the `max-width` and `max-height` constraints of the host HTML element
83+
84+
:::important
85+
**File size optimization** and maintaining **aspect ratio** uses features provided by Stream's CDN. If you're using your **own CDN** you'll likely have to provide your own implementation for this. You can do this using the [`AttachmentConfigurationService`](../services/AttachmentConfigurationService.mdx).
86+
:::
87+
88+
:::danger
89+
**If you're planning to rewrite attachment sizing with your own CSS code** it's important to note that:
90+
91+
The sizing logic for images and videos inside the [`AttachmentConfigurationService`](../services/AttachmentConfigurationService.mdx) requires that host elements of images and videos (ususally `img` and `video` elements) have `max-height`/`height` and `max-width` properties defined and that these values can be computed to a valid pixel value using the [`getComputedStyle`](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle).
92+
:::
93+
4394
[//]: # "Start of generated content"
4495
[//]: # "End of generated content"

0 commit comments

Comments
 (0)