You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following section details how the width and height of images and videos uploaded from files are computed.
112
+
113
+
#### Maximum size
114
+
115
+
You can control the maximum width and height 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).
116
+
117
+
If you set an invalid value to the variable, you'll see a warning on the browser's console:
118
+
119
+
<img src={AttachmentSizeWarning} width='800' />
120
+
121
+
#### File size optimization
122
+
123
+
Based on the CSS settings provided for images and videos (see [Maximum size](#maximum-size) section), 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.
124
+
125
+
For example if an image has `max-width` and `max-height` set to `300px` and the original image has the following dimensions: `965 × 1280` it's enough to load an image with a reduced file size, file size reduction is done by Stream's CDN.
126
+
127
+
#### Aspect ratio
128
+
129
+
The following description is applicable for [theme-v2](../theming/introduction.mdx).
130
+
131
+
The SDK will try to display images and videos with their original aspect ratio, however this isn't always guaranteed (in those cases a cropped image will be displayed). Three notable exceptions are:
132
+
133
+
1. if a message contains multiple lines of texts and/or multiple attachments, the image/video might be stretched to its `max-width`
134
+
135
+
**Example 1** - message with one line of text - image is displayed with original aspect ratio
136
+
137
+
<img src={ImageSizingScreenshot1} width='200' />
138
+
139
+
**Example 2** - message with multiple lines of text - image is cropped
140
+
141
+
<img src={ImageSizingScreenshot2} width='200' />
142
+
143
+
2. in Safari, images/videos with portrait orientation are stretched to `max-width`
144
+
145
+
**Example 3** - portrait images in Safari - image is cropped
146
+
147
+
<img src={ImageSizingScreenshot3} width='200' />
148
+
149
+
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
150
+
151
+
:::important
152
+
**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 [`imageAttachmentSizeHandler`](../core-components/channel.mdx/#imageattachmentsizehandler) and [`videoAttachmentSizeHandler`](../core-components/channel.mdx/#videoattachmentsizehandler) props.
153
+
:::
154
+
155
+
:::danger
156
+
**If you're planning to rewrite attachment sizing with your own CSS code** it's important to note that:
157
+
158
+
The sizing logic for images and videos (the [`imageAttachmentSizeHandler`](../core-components/channel.mdx/#imageattachmentsizehandler) and [`videoAttachmentSizeHandler`](../core-components/channel.mdx/#videoattachmentsizehandler)) 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) (for more information refer to the [Maximum size](#maximum-size) section).
0 commit comments