# Image scaling not working if alt text is missing

**URL:** https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883
**Category:** Bug
**Created:** [February 16, 2021, 1:37pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883 "2021-02-16T13:37:03Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [February 16, 2021, 1:37pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/1 "2021-02-16T13:37:04Z")

</div>

Not sure if it’s intended behavior or a bug, but the `%` buttons for scaling images and the actual scaling doesn’t work anymore if the image lacks an alt text, which used to work before a recent (week-ish?) update.

If there are more images in the post and one of them is missing the alt text, if you click its `%` buttons it changes the scaling for **another** image that has the alt text ( **EDIT** : I just changed the category to #Contribute > Bug because, even if the alt text was needed, this shouldn’t happen)

This doesn’t work, but used to:  
`![690x184, 40%](upload://hash)`

Adding the `alt|` part before the image size fixes it, as expected.

I need to update some topics to adapt to this – or otherwise these images would be at 100% if rebaked eventually – and I realized this could be the case for others as well, hence this post.

---

<div class="post-metadata">

### Author: ![jomaxro](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jomaxro/32/126216_2.png) [@jomaxro](https://meta.discourse.org/u/jomaxro)
#### Post date: [February 16, 2021, 8:43pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/2 "2021-02-16T20:43:18Z")

</div>

Can repro, removing the alt text breaks image scaling.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [February 17, 2021, 11:06pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/3 "2021-02-17T23:06:23Z")

</div>

> [@renato](#):
>
> This doesn’t work, but used to:

Hmm, what are your feelings on this one @sam?

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 17, 2021, 11:21pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/4 "2021-02-17T23:21:52Z")

</div>

I do not think this ever worked without the alt text, I guess we could support it,

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [February 17, 2021, 11:28pm UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/5 "2021-02-17T23:28:13Z")

</div>

It did work, I have several topics in my instance with the correct scaling and missing the alt text. If I rebake any of them the scaling is gone.

**EDIT** : Maybe related to [this change](https://github.com/discourse/discourse/commit/830797a9c3f82f66c882c0e33f9fa08551db0af2?branch=830797a9c3f82f66c882c0e33f9fa08551db0af2&diff=split#diff-c3fd8526b122e54763bc01af0ccb85a6ceda9b1775493b8ebcfc496ce1f721ff)?

I couldn’t find anything that would explain the difference on post cooking, though.

I don’t mind editing those topics, but others may also face this situation and the resize controls on the `alt`-less image shouldn’t change **another** image’s scale

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 18, 2021, 12:40am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/6 "2021-02-18T00:40:55Z")

</div>

Fair enough, if you are sure it worked previously I believe you 100%.

@david I guess this could have been your regression here, seems simple enough to fix?

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [February 18, 2021, 12:54am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/7 "2021-02-18T00:54:37Z")

</div>

Yeah looks like this was my change. I had assumed the previous implementation was a bug. All our tests assume the dimensions will be after a `|` character:

> <https://github.com/discourse/discourse/blob/c4ff6def8eeca471cd4b75ddc41e8355248b376d/spec/components/pretty_text_spec.rb#L1527-L1533>

I could revert us back to the old behaviour, and add a test to make sure it keeps working. But doing that means that you can never have an image with alt text like `123x123`.

@renato do you know how you ended up without any pipe character in the markdown? As far as I know, all the UI options should generate it with a pipe 🤔

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [February 18, 2021, 1:26am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/8 "2021-02-18T01:26:40Z")

</div>

> [@david](#):
>
> @renato do you know how you ended up without any pipe character in the markdown? As far as I know, all the UI options should generate it with a pipe 🤔

Yes, the posts where I noticed this behavior were all created using the API with a preset raw content that was tested before in the UI. I deliberately removed the alt texts of two images that wouldn’t make much sense in a screen reader.

I don’t mind adapting to the new behavior if that’s what you end up deciding.

_Off-topic_: may I ask for a plugin recommendation that changes `[something]` to some raw content as inspiration for a plugin of my own? This way I could do just another edit on all those topics and if I eventually need to change them again, a rebake would be enough.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 18, 2021, 1:29am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/9 "2021-02-18T01:29:51Z")

</div>

Yeah I think it is better to adapt to the new way here. We never really intended to support this. Wider support for more formats means more code in the backend and more testing.

> [@renato](#):
>
> may I ask for a plugin recommendation that changes `[something]` to some raw content as inspiration for a plugin of my own? This way I could do just another edit on all those topics and if I eventually need to change them again, a rebake would be enough.

Simplest would be to use db remap see: [Replace a string in all posts - Self-Hosting - Discourse Meta](https://meta.discourse.org/docs?search=remap&topic=48729)

---

<div class="post-metadata">

### Author: ![renato](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/renato/32/383632_2.png) [@renato](https://meta.discourse.org/u/renato)
#### Post date: [February 18, 2021, 1:41am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/10 "2021-02-18T01:41:21Z")

</div>

> [@sam](#):
>
> Yeah I think it is better to adapt to the new way here

OK, let me just keep the suggestion to only show the scale buttons on images that can be scaled.

> [@sam](#):
>
> Simplest would be to use db remap see: [Replace a string in all posts - Docs - Discourse Meta](https://meta.discourse.org/docs?search=remap&topic=48729)

Oh yes, for this specific change I can do this, thanks. Anyway, this isn’t the only place I’ve a preset raw content managed by an external service, maybe I could get some ideas from [poll](https://github.com/discourse/discourse/tree/master/plugins/poll) – or if you recall a simpler one, please let me know.

Thank you and sorry for so much noise for this small issue.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 18, 2021, 1:44am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/11 "2021-02-18T01:44:39Z")

</div>

> [@renato](#):
>
> sorry for so much noise for this small issue.

Not at all, thanks for bringing this up and being so patient with us.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [February 18, 2021, 1:44am UTC](https://meta.discourse.org/t/image-scaling-not-working-if-alt-text-is-missing/179883/12 "2021-02-18T01:44:53Z")

</div>


