Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebP images don’t work in og:image (external link previews) #14983

Open
da2x opened this issue Oct 14, 2020 · 26 comments
Open

WebP images don’t work in og:image (external link previews) #14983

da2x opened this issue Oct 14, 2020 · 26 comments

Comments

@da2x
Copy link
Contributor

da2x commented Oct 14, 2020

Expected behaviour

Toots with WebP images in their OpenGraph thumbnail image in WebP format should work as a preview image in Mastodon. (<meta name="og:image" content="https://example.com/image.webp">)

Actual behaviour

The toot is shown with the default image. The external image (WebP format) fails to load.

Steps to reproduce the problem

Share any link from e.g. reddit.com (any thread that’s shown in their interface with an image) or ctrl.blog and open the toot in the web interface.

Specifications

Firefox 81 on Fedora 32 and Windows 10.

Related

#14819 SVG support

@Gargron
Copy link
Member

Gargron commented Oct 14, 2020

I can't fix this, imagemagick lacks proper webp support

@SuperSandro2000
Copy link
Contributor

Maybe ImageMagick needs an update because on their website they list quite a few options for webp. https://imagemagick.org/script/webp.php

@charlag
Copy link

charlag commented Apr 9, 2022

That kinda sucks from the user perspective when you can't upload pics from e.g. reddit and you don't know why, regardless of whether it should be served to the clients as webp or not

@ayushnix
Copy link

I can't fix this, imagemagick lacks proper webp support

Does imagemagick properly support webp now?

@pauloxnet
Copy link
Contributor

I can't fix this, imagemagick lacks proper webp support

It seems to me that imagemagick now support well the webp format since a while
https://imagemagick.org/script/webp.php

It's also one of the main format advertise in the imagemagick home Page
https://imagemagick.org/

@pauloxnet
Copy link
Contributor

pauloxnet commented Nov 15, 2022

I think the support has been added in 379a7a7

@da2x @Gargron this issue can be closed.

@pauloxnet
Copy link
Contributor

Can anyone close this issue?

Here my last toot as demonstration that mastodon now can correctly render preview card using og:image file in WebP format
https://fosstodon.org/@paulox/109395028585159669

@THeK3nger
Copy link

THeK3nger commented Jan 20, 2023

It is actually still broken for me. I cannot see the og:image preview in my blog's links (nor in the previous example).

(Even third-party clients cannot load them. Does it still depends on the main Mastodon code?)

EDIT: Yep. At least on v4.0.2, if I convert the og:image to png everything works. With webp, I get nothing.

@quicoto
Copy link

quicoto commented Mar 9, 2023

@THeK3nger I was looking for a way to show bigger image preview and stumbled across your issue

I'm using webp and I do see a preview in 4.1.0

Example post: https://ricard.social/@ricard/109992959202878541

@LeoEurope
Copy link

LeoEurope commented Apr 24, 2023

Link previews for many sites don’t show the OpenGraph Image because the image is WebP or AVIF. See also: #18762

Now, there are other issues I don’t understand but are perhaps related.

Solution?
ImageMagick now supports both WebP and AVIF but the server doesn't, and many Mastodon clients may not. The use of WebP and AVIF will only increase in future. Is it an idea to require ImageMagick with WebP and AVIF support (it looks like a compile time option) and convert all WebP and AVIF images to PNG (or even high quality JPG) until support for those formats in clients has improved?

A solution for non-standard or buggy JPGs might be to have ImageMagick rewrite the JPGs without further compression. I assume it's currently already stripping privacy sensitive information (EXIF) from images anyway.

@tomresing
Copy link

Is it possible that the solution is as simple as including the instructions to download and install libwebp?

I'm a novice at ImageMagick and Mastodon installation, but after I installed ImageMagick on my device it didn't support WebP until I also installed libwebp as suggested in the ImageMagick community.

@tomresing
Copy link

I don't see libwebp listed in the system packages in the Mastodon install documentation. I do see libwebp in the list of available packages for both Debian and Ubuntu.

@c960657
Copy link
Contributor

c960657 commented Jul 27, 2023

@LeoEurope The issue with The Guardian is not related to WebP – see #26219.

Now, there are other issues I don’t understand but are perhaps related.

Some of them are skipped, because the file size of the Open Graph image is above the 1 MB limit. I think it would be reasonable to increase this limit a bit.

@LeoEurope
Copy link

@LeoEurope The issue with The Guardian is not related to WebP – see #26219.

That could play a role, yes. But I doubt it's the only one. Check this image link from The Guardian: https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none The URL suggests that it's a JPG but Firefox actually receives it as an AVIF file. If I open the same link in an older version of Safari that I have lying around it's sent as a JPG.

That suggests that, server side, some sniffing is happening to send an WebP or AVIF file even if the extension is .jpg. The Mastodon server might be receiving an AVIF and doesn't know what to do with it.

@c960657
Copy link
Contributor

c960657 commented Jul 30, 2023

The server returns different file formats depending the Accept header. This is why Firefox receives an AVIF file.

$ curl -s -H 'Accept: image/avif, *' -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/avif

$ curl -s -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/jpeg

@tomresing
Copy link

The server returns different file formats depending the Accept header. This is why Firefox receives an AVIF file.

$ curl -s -H 'Accept: image/avif, *' -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/avif

$ curl -s -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/jpeg

Very helpful to see the difference in the responses from the two requests for the same resource. Do we know which accept header Mastodon is sending? Do you have a similar request that returns the size of the image?

@LeoEurope
Copy link

The server returns different file formats depending the Accept header. This is why Firefox receives an AVIF file.

$ curl -s -H 'Accept: image/avif, *' -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/avif

$ curl -s -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/jpeg

Very helpful to see the difference in the responses from the two requests for the same resource. Do we know which accept header Mastodon is sending? Do you have a similar request that returns the size of the image?

That's a good point, the find by @c960657 makes me think a quick first solution would be to have the Mastodon server only send image/jpg and image/png accept headers when getting the Preview image until WebP and AVIF support is fixed.

Over time it makes sense to also support WebP and AVIF as that will have considerable impact on storage use by all servers.

@c960657
Copy link
Contributor

c960657 commented Aug 4, 2023

Do we know which accept header Mastodon is sending?

It doesn't send any.

Do you have a similar request that returns the size of the image?

The file size is bytes can be measured like this:

$ curl -s 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | wc -c
   48074

@tomresing
Copy link

@c960657 is the header passed from the Mastodon client through to the end web server then? I'm not sure why you mentioned that that it sends back different image formats based on the header. It might be that the fix @LeoEurope suggests is the PR needed to resolve this issue, but it seems like you're suggesting the normalize URL PR you've submitted will solve the issue without a header change.

@Sushubh
Copy link

Sushubh commented Sep 20, 2023

at my end... og:image webp images seem to work when the image is on the same domain as the shared link. if the image is third party, it does not appear. third party jpegs however do appear so the issue does not seem to be third party image. just a fyi.

@phocks
Copy link
Contributor

phocks commented May 7, 2024

Link previews for many sites don’t show the OpenGraph Image because the image is WebP or AVIF. See also: #18762

* Take this link from The Guardian: https://www.theguardian.com/environment/2023/apr/24/european-countries-pledge-huge-expansion-of-north-sea-wind-farms When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110254671877149700 because the OG image is WebP.

* Or this link from Euronews, it claims to send a JPG but some browser detection actually makes it send a Webp: https://www.euronews.com/next/2023/05/22/this-british-start-up-has-designed-an-umbrella-like-landing-system-to-make-satellites-reus When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110413336447544332

* Or this link from the Financial Times: https://www.ft.com/content/358e382d-ba54-46d0-8b34-22910dbe7cec When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110077571317654160 because the OG image is AVIF.

Now, there are other issues I don’t understand but are perhaps related.

* This article serves a PNG as OG Image: https://www.spiegel.de/international/europe/britain-in-crisis-the-uk-faces-a-steep-climb-out-of-a-deep-hole-a-6b61dc6f-e33f-46f3-bd27-743364dd675c but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110225054846515314

* Another example with a PNG: https://www.wired.co.uk/article/qanon-conspiracy-bodegraven-netherlands vs https://mstdn.social/@TheEuropeanNetwork/110186271930242074

* This article serves a JPG as OG Image: https://www.rte.ie/news/2023/0416/1377262-finland-reactor/ but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110212988501999628

* This article serves a JPG as OG Image: https://www.bloomberg.com/news/features/2023-05-16/from-traffic-choked-brussels-a-model-for-driving-less but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110395364546446410

* This article's og:image works fine in the web client, the official Mastodon app, and the MetaText app, but it doesn't work in the Ice Cubes app. It may be an app specific issue, though. https://euobserver.com/green-economy/157251

Solution? ImageMagick now supports both WebP and AVIF but the server doesn't, and many Mastodon clients may not. The use of WebP and AVIF will only increase in future. Is it an idea to require ImageMagick with WebP and AVIF support (it looks like a compile time option) and convert all WebP and AVIF images to PNG (or even high quality JPG) until support for those formats in clients has improved?

A solution for non-standard or buggy JPGs might be to have ImageMagick rewrite the JPGs without further compression. I assume it's currently already stripping privacy sensitive information (EXIF) from images anyway.

This seems like the only good solution from @LeoEurope. Simply convert the webp avif etc images to jpegs and be done with it.

@phocks
Copy link
Contributor

phocks commented May 9, 2024

The server returns different file formats depending the Accept header. This is why Firefox receives an AVIF file.

$ curl -s -H 'Accept: image/avif, *' -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/avif

$ curl -s -I 'https://i.guim.co.uk/img/media/b5bd441e246054953dbc21d57ab9667093036ead/0_346_6048_3628/master/6048.jpg?width=620&dpr=1&s=none' | grep -i content-type
content-type: image/jpeg

@c960657 anyone know where the code is that fetches the images in the codebase? Should be a pretty easy fix?

Edit: I found this. Surely it wouldn't be just as simply as removing the image/webp from here. og spec says it only works with jpg png and gif

og:image:type - MIME type of the image. One of image/jpeg, image/gif or image/png

class PreviewCard < ApplicationRecord
include Attachmentable
IMAGE_MIME_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'].freeze
LIMIT = 2.megabytes

I'll keep searching. I guess it doesn't explain the avif images. And I guess this file does something with the images in the database or something. Not sure, I don't really know Ruby that well.

Edit 2: I found this. Might be something. Might have a look later when I'm free.

@card.embed_url = (url + embed[:url]).to_s
@card.image_remote_url = (url + embed[:url]).to_s

I think we're probably on the right track here. Just need to find where it actually constructs the http request right?

def to_preview_card_attributes
{
title: title || '',
description: description || '',
image_remote_url: image,
image_description: image_alt || '',
type: type,
link_type: link_type,
width: width || 0,
height: height || 0,
html: html || '',
provider_name: provider_name || '',
provider_url: provider_url || '',
author_name: author_name || '',
author_url: author_url || '',
embed_url: embed_url || '',
language: language,
published_at: published_at.presence,
}

@LeoEurope
Copy link

LeoEurope commented May 11, 2024

Link previews for many sites don’t show the OpenGraph Image because the image is WebP or AVIF. See also: #18762

* Take this link from The Guardian: https://www.theguardian.com/environment/2023/apr/24/european-countries-pledge-huge-expansion-of-north-sea-wind-farms When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110254671877149700 because the OG image is WebP.

* Or this link from Euronews, it claims to send a JPG but some browser detection actually makes it send a Webp: https://www.euronews.com/next/2023/05/22/this-british-start-up-has-designed-an-umbrella-like-landing-system-to-make-satellites-reus When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110413336447544332

* Or this link from the Financial Times: https://www.ft.com/content/358e382d-ba54-46d0-8b34-22910dbe7cec When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110077571317654160 because the OG image is AVIF.

Now, there are other issues I don’t understand but are perhaps related.

* This article serves a PNG as OG Image: https://www.spiegel.de/international/europe/britain-in-crisis-the-uk-faces-a-steep-climb-out-of-a-deep-hole-a-6b61dc6f-e33f-46f3-bd27-743364dd675c but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110225054846515314

* Another example with a PNG: https://www.wired.co.uk/article/qanon-conspiracy-bodegraven-netherlands vs https://mstdn.social/@TheEuropeanNetwork/110186271930242074

* This article serves a JPG as OG Image: https://www.rte.ie/news/2023/0416/1377262-finland-reactor/ but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110212988501999628

* This article serves a JPG as OG Image: https://www.bloomberg.com/news/features/2023-05-16/from-traffic-choked-brussels-a-model-for-driving-less but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110395364546446410

* This article's og:image works fine in the web client, the official Mastodon app, and the MetaText app, but it doesn't work in the Ice Cubes app. It may be an app specific issue, though. https://euobserver.com/green-economy/157251

Solution? ImageMagick now supports both WebP and AVIF but the server doesn't, and many Mastodon clients may not. The use of WebP and AVIF will only increase in future. Is it an idea to require ImageMagick with WebP and AVIF support (it looks like a compile time option) and convert all WebP and AVIF images to PNG (or even high quality JPG) until support for those formats in clients has improved?
A solution for non-standard or buggy JPGs might be to have ImageMagick rewrite the JPGs without further compression. I assume it's currently already stripping privacy sensitive information (EXIF) from images anyway.

This seems like the only good solution from @LeoEurope. Simply convert the webp avif etc images to jpegs and be done with it.

There's now PR #30090 about replacing ImageMagick with libvips, which might solve the underlying issue of WebP and AVIF support.

I'd suggest to use this bug to solve any WebP/AVIF problems that may still occur after libvips has landed and consider using #27370 as a temporary stopgap by sending HTTP AcceptHeaders to stop servers sending WebP and AVIF until this is solved (if necessary).

@phocks
Copy link
Contributor

phocks commented May 17, 2024

I have done some poking around in the Mastodon code and it seems I've traced some preview card issues to an unlikely source.

def body_with_limit(limit = 1.megabyte)

If an article page's html content is larger than 1MB (like Wired and The New Yorker) then an error is raised and the preview card doesn't show.

If we set the limit to 2MB the preview card displays as normal.

ps. your site html really shouldn't be more than 1MB yet here we are

def body_with_limit(limit = 1.megabyte)

(from my toot https://bne.social/@phocks/112458999544660059)

I think bumping this up to 2MB makes sense in 2024

@phocks
Copy link
Contributor

phocks commented May 19, 2024

OK I've created a pull request. Seems like the truncated_body function was adding the chunk of html to the contents and THEN stopping after that, which meant that the contents.bytesize was ALWAYS going to be over the limit and so the exception is always raised when the html is over 1MB (such as New Yorker and Wired articles).

This just makes the break before adding the chunk, so contents remains just under the limit.

Who do I need to ping to get this approved? @Gargron ? @renchap ?

Cheers!

@renchap
Copy link
Sponsor Member

renchap commented May 19, 2024

Looks like there is a lot of confusion going on here.

Take this link from The Guardian: https://www.theguardian.com/environment/2023/apr/24/european-countries-pledge-huge-expansion-of-north-sea-wind-farms

Fixed by #26219

Or this link from Euronews, it claims to send a JPG but some browser detection actually makes it send a Webp: https://www.euronews.com/next/2023/05/22/this-british-start-up-has-designed-an-umbrella-like-landing-system-to-make-satellites-reus When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110413336447544332

The image is correctly a JPEG, it appears as a WebP in your browser because your browser sends Accept headers. The issue here is not related to the image format

Or this link from the Financial Times: https://www.ft.com/content/358e382d-ba54-46d0-8b34-22910dbe7cec When posted to Mastodon it looks like this: https://mstdn.social/@TheEuropeanNetwork/110077571317654160 because the OG image is AVIF.

There are no OG or oembed tags for this URL, this is why there is no preview image

This article serves a PNG as OG Image: https://www.spiegel.de/international/europe/britain-in-crisis-the-uk-faces-a-steep-climb-out-of-a-deep-hole-a-6b61dc6f-e33f-46f3-bd27-743364dd675c but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110225054846515314

The Opengraph image is more than 1 MB, so it is ignored by Mastodon. We might bump this once the libvips PR is merged

Another example with a PNG: https://www.wired.co.uk/article/qanon-conspiracy-bodegraven-netherlands vs https://mstdn.social/@TheEuropeanNetwork/110186271930242074

Same

This article serves a JPG as OG Image: https://www.rte.ie/news/2023/0416/1377262-finland-reactor/ but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110212988501999628

Same, with a 5 MB image

This article serves a JPG as OG Image: https://www.bloomberg.com/news/features/2023-05-16/from-traffic-choked-brussels-a-model-for-driving-less but it doesn’t come through when posted in Mastodon: https://mstdn.social/@TheEuropeanNetwork/110395364546446410

May be blocked by Bloomberg's bot detection (need to investigate more)

This article's og:image works fine in the web client, the official Mastodon app, and the MetaText app, but it doesn't work in the Ice Cubes app. It may be an app specific issue, though. https://euobserver.com/green-economy/157251

Link preview generation is made on the backend, so not sure what is happening here, but this is not a Mastodon issue

As you can see, none of those are caused by having a WebP of AVIF image, neither by HTML documents being over the 1 MB limit.

We will consider upping the OG image limit once #30090 is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests