Image scaling not working if alt text is missing

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 #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.

1 Like

Can repro, removing the alt text breaks image scaling.

2 Likes

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

1 Like

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

2 Likes

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?

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

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?

4 Likes

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:

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 :thinking:

6 Likes

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.

2 Likes

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.

Simplest would be to use db remap see: Replace a string in all posts - Docs - Discourse Meta

3 Likes

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

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 – or if you recall a simpler one, please let me know.

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

3 Likes

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

3 Likes