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
Comments
I can't fix this, imagemagick lacks proper webp support |
Maybe ImageMagick needs an update because on their website they list quite a few options for webp. https://imagemagick.org/script/webp.php |
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 |
Does imagemagick properly support webp now? |
It seems to me that imagemagick now support well the webp format since a while It's also one of the main format advertise in the imagemagick home Page |
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 |
It is actually still broken for me. I cannot see the (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 |
@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 |
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? 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. |
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. |
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. |
@LeoEurope The issue with The Guardian is not related to WebP – see #26219.
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. |
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. |
The server returns different file formats depending the
|
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. |
It doesn't send any.
The file size is bytes can be measured like this:
|
@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. |
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. |
This seems like the only good solution from @LeoEurope. Simply convert the webp avif etc images to jpegs and be done with it. |
@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
mastodon/app/models/preview_card.rb Lines 37 to 42 in d8c4284
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. mastodon/app/services/fetch_link_card_service.rb Lines 129 to 130 in d8c4284
I think we're probably on the right track here. Just need to find where it actually constructs the http request right? mastodon/app/lib/link_details_extractor.rb Lines 113 to 131 in d8c4284
|
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). |
I have done some poking around in the Mastodon code and it seems I've traced some preview card issues to an unlikely source.
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 Line 236 in 2da2a1d
(from my toot https://bne.social/@phocks/112458999544660059) I think bumping this up to 2MB makes sense in 2024 |
OK I've created a pull request. Seems like the 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! |
Looks like there is a lot of confusion going on here.
Fixed by #26219
The image is correctly a JPEG, it appears as a WebP in your browser because your browser sends
There are no OG or oembed tags for this URL, this is why there is no preview image
The Opengraph image is more than 1 MB, so it is ignored by Mastodon. We might bump this once the libvips PR is merged
Same
Same, with a 5 MB image
May be blocked by Bloomberg's bot detection (need to investigate more)
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. |
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
The text was updated successfully, but these errors were encountered: