Images size properly in the preview window, but not in the post

AI-generated summary

In a bug report regarding Discourse v1.4.0.beta1, Itzikiap noted that while <img> tags with explicit width attributes display correctly in the preview window, images revert to their natural size after the post is saved. This issue persists in previous versions. cipher1 suggested that the problem might stem from missing quotes around the width value and provided corrected examples. However, testing revealed that while adding quotes works for new posts, it fails to update the baked version of existing posts. Ultimately, codinghorror clarified that arbitrarily setting image sizes via HTML tags is not supported in Discourse; users must resize images using an image editor to achieve a fixed width.

Hi. my discourse installation is:
v1.4.0.beta1

When I edit a post, I can write img tags for images, and set the size of the image to fit my post, and not be so big. As you can see in the screen shot, in the preview it works.
(Don’t mind the alignment of the text in the edit, I just temporarly aligned it to the left so it would be more convenient to write the img tags)

However, after accepting the edit and savig, all the images are displayed in their natural size, regardless of what I wrote.

This is the img line:

<img src='/uploads/default/original/1X/0d1549f080237ad08a753deb0f8b7fb2e28d3852.gif' width=100>

This problem was also in previous versions of discourse.

Thanks.

You appear to be missing the proper quotes around the width value in your tag. Try using:

<img src='/uploads/default/original/1X/0d1549f080237ad08a753deb0f8b7fb2e28d3852.gif' width='100'>

or

<img src="/uploads/default/original/1X/0d1549f080237ad08a753deb0f8b7fb2e28d3852.gif" width="100">

If that doesn’t fix it, then it probably has something to do with how Discourse bakes the lightboxes for larger images.

Edit: Testing on try.discourse shows that using the examples I provided when initially posting works as intended, but trying to go from what @Itzikiap is using to one of my examples by editing an existing post does not correct the baked version of the post.

1 Like

Setting image sizes arbitrarily is not supported. If you want a fixed width, resize the image in an image editor to be width=100.