Page MenuHomePhabricator

Duplicate og:image on Wikipedia and Wikidata (There are too many faces of Tom Hanks)
Closed, ResolvedPublic

Assigned To
Authored By
Krinkle
Nov 11 2021, 4:22 AM
Referenced Files
F65976956: screenshot 119.png
Sep 6 2025, 8:25 PM
F65976953: screenshot 118.png
Sep 6 2025, 8:25 PM
F65795951: Screenshot 4.png
Aug 20 2025, 1:40 AM
F65795952: Screenshot 3.png
Aug 20 2025, 1:40 AM
F65795947: Screenshot 2.png
Aug 20 2025, 1:40 AM
F65795948: Screenshot 1.png
Aug 20 2025, 1:40 AM
F65795958: Screenshot 6.png
Aug 20 2025, 1:40 AM
F65795957: Screenshot 5.png
Aug 20 2025, 1:40 AM

Description

Background

[…] done intentionally to support Whatsapp which has a 300kb limit on byte size for images. Ideally there would be one which is guaranteed to be under < 300kb but I don't think there is a function that can be called to say "give me a thumbnail with these dimensions which has a file size less than 300kb.

It's only recently I believe that certain clients have started to display multiple images when multiple tags are present.

Bug report

Steps:

  1. Share https://en.wikipedia.org/wiki/Tom_Hanks or https://www.wikidata.org/wiki/Q2263 as link via a social app that generates a preview card (e.g. Apple iMessage).

Expected:
One image.

Actual:
Three identical images.

Other information:

  1. https://www.wikidata.org/wiki/Q2263, observe there is only one image associated with the item.
  2. View source and look for <meta .. og:image, where there are three images:
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/a/a9/Tom_Hanks_TIFF_2019.jpg"/>
<meta property="og:image:width" content="1200"/>
<meta property="og:image:height" content="1670"/>
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Tom_Hanks_TIFF_2019.jpg/800px-Tom_Hanks_TIFF_2019.jpg"/>
<meta property="og:image:width" content="800"/>
<meta property="og:image:height" content="1113"/>
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Tom_Hanks_TIFF_2019.jpg/640px-Tom_Hanks_TIFF_2019.jpg"/>
<meta property="og:image:width" content="640"/>
<meta property="og:image:height" content="890"/>

Screenshot 2021-11-11 at 04.18.50.png (742×500 px, 641 KB)

Requirement

Scope: Desktop and mobile web. Pages must include only a single og:image tag in the HTML metadata:

  • Open Graph metadata should not duplicate the same image at multiple resolutions.
  • Verification applies to Wikipedia article pages and Wikidata entity pages.

BDD

Feature: Prevent duplicate og:image tags

  Scenario: Wikipedia article page metadata
    Given I visit a Wikipedia article page with an image (e.g., Tom Hanks)
    When I inspect the HTML source for <meta property="og:image">
    Then only one og:image tag is present
    And no duplicate entries for different resolutions exist

  Scenario: Wikidata entity page metadata
    Given I visit a Wikidata entity page with an image (e.g., Q2263)
    When I inspect the HTML source for <meta property="og:image">
    Then only one og:image tag is present
    And no duplicate entries for different resolutions exist

Test Steps

Test Case 1: Wikipedia article page has single og:image tag

  1. Open https://en.wikipedia.org/wiki/Tom_Hanks.
  2. Inspect page source or use DevTools Elements panel.
  3. Search for <meta property="og:image".
  4. AC1: Exactly one og:image tag is present.
  5. AC2: No duplicate og:image tags exist for different resolutions.

Test Case 2: Wikidata entity page has single og:image tag

  1. Open https://www.wikidata.org/wiki/Q2263.
  2. Inspect page source or use DevTools Elements panel.
  3. Search for <meta property="og:image".
  4. AC3: Exactly one og:image tag is present.
  5. AC4: No duplicate og:image tags exist for different resolutions.

QA Results - Prod

Event Timeline

Yeah, this seems like a bug. https://ogp.me/#array says that multiple og:image values are allowed, but it sounds like they’re intended for different images, not alternative resolutions of the same image. (It doesn’t look like there’s anything like <picture> for og:image.)

By the way, this does affect Wikipedia as well, e.g.:

Screenshot 2022-04-12 at 20.02.04.png (602×560 px, 392 KB)

(My previous example was from Wikidata.)

Jdlrobson subscribed.

If I recall correctly this was done intentionally to support Whatsapp which has a 300kb limit on byte size for images. Ideally there would be one which is guaranteed to be under < 300kb but I don't think there is a function that can be called to say "give me a thumbnail with these dimensions which has a file size less than 300kb.

It's only recently I believe that certain clients have started to display multiple images when multiple tags are present. @Krinkle which client are you seeing these multiple images displayed - that will likely be helpful to Olga for prioritization.

macOS Messages (Apple iMessage).

ovasileva triaged this task as Medium priority.Jun 7 2022, 8:57 AM

Apparently, Discord has changed the way it displays embeds and now it displays 3 images, too. It was displaying only one until today.

imagen.png (433×538 px, 217 KB)

Can confirm the Discord issue, it also exists for the Associated Press which shows two images.

This seems fixed at Discord's side again, at least in my client.

Per the web team's quarterly grooming, these tasks are being removed from the team's backlog.

Fixed confusing markup and unattributed text.

Screenshot 2025-01-27 at 19.53.07.png (468×458 px, 48 KB)

Given that WhatsApp doesn't even display the images, I suggest we simplify things and remove the duplicate og:image tags, keeping only the high-resolution one (and clients can downscale as needed).

Change #1172876 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/PageImages@master] Stop sending more than one og:image to social media platforms

https://gerrit.wikimedia.org/r/1172876

WhatsApp's docs at https://developers.facebook.com/docs/whatsapp/link-previews/ now state: "The <og:image> mark-up is an absolute URL for an image used as the thumbnail for the link preview. This image should be under 600KB in size. Image should be 300px or more in width with 4:1 width/height or less aspect ratio". So perhaps it would be better only to output one tag (640px in width, maybe?) even when it comes to supporting previews in WhatsApp.

Test wiki created on Patch demo by Simon04 using patch(es) linked to this task:
https://7fd295f885.catalyst.wmcloud.org/w/

Test wiki on Patch demo by Simon04 using patch(es) linked to this task was deleted:

https://7fd295f885.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by Simon04 using patch(es) linked to this task:
https://c6a1e088d6.catalyst.wmcloud.org/w/

Change #1172876 merged by jenkins-bot:

[mediawiki/extensions/PageImages@master] Stop sending more than one og:image to social media platforms

https://gerrit.wikimedia.org/r/1172876

Jdlrobson-WMF subscribed.

I am no longer seeing any thumbnails on Whatsapp for test.wikipedia.org following the change.

Tagging reader experience since this could impact a key metric.

Change #1180203 had a related patch set uploaded (by Thiemo Kreuz (WMDE); author: Thiemo Kreuz (WMDE)):

[mediawiki/extensions/PageImages@master] Fix mistake when sending og:image to social media platforms

https://gerrit.wikimedia.org/r/1180203

Change #1180201 had a related patch set uploaded (by Krinkle; author: Jdlrobson):

[mediawiki/extensions/PageImages@master] Revert "Stop sending more than one og:image to social media platforms"

https://gerrit.wikimedia.org/r/1180201

Change #1180201 merged by jenkins-bot:

[mediawiki/extensions/PageImages@master] Revert "Stop sending more than one og:image to social media platforms"

https://gerrit.wikimedia.org/r/1180201

I’ve verified that the revert is working using a cache-busting query string parameter. With caching, it will take some time before the change is reflected on group 0 wikis.

Screenshot 2025-08-19 at 2.41.46 PM.png (306×918 px, 107 KB)

When attempting the patch again, it would be a good idea to request a review from the Reader Experience Team. They can help check integrations like WhatsApp pre-merge and post-merge (Steph T is the current tech lead and the PM is HFan-WMF).

Just a reminder: PageImages doesn’t currently have a dedicated maintaining team (T252249: PageImages extension: Code stewardship review), but it’s critical to many of our systems, so any feature changes should be made with extra care.

Thanks in advance!

Change #1180203 merged by jenkins-bot:

[mediawiki/extensions/PageImages@master] Fix duplicate og:image in message previews (take 2)

https://gerrit.wikimedia.org/r/1180203

Thanks for catching that bug, @Jdlrobson-WMF. It looks like the most important part of the og:image feature lacks test coverage (doc.wikimedia.org link).

Screenshot 2025-08-20 at 00.53.07.png (1×2 px, 296 KB)

I've verified take 2 in the Beta Cluster (in next week's train, not this week). Specifically:

  1. What worked before still works.
  2. Fixed bug of no preview for tall images in WhatsApp.
  3. Fixed bug of three duplicate images in Apple Messages (could not reproduce today, Apple now displays one instead of multiple images)

The second point is because to Thiemo's approach considers both width and height (instead of only the width). Previously, it would return a file notably larger than 1200px/600KB for images with a tall aspect ratio.

It also fixes an issue with dangling image dimension blocks without an actual image to go along with them. For example, at https://en.wikipedia.org/wiki/Tom_Hanks right now. I suspect this may be due to unavailable thumbnail sizes (the previous code did not check the return value), although thumbnail failures should be rare and would not affect all featured articles as this bug does currently. It looks like it might be OutputPage de-duplication causing it, because 640px and 800px both round to 960px per $wgThumbnailSteps.

<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/3/39/TomHanksPrincEdw031223_%2811_of_41%29_%28cropped%29.jpg">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="1665">
<meta property="og:image" content="https://upload.wikimedia.org/wikipedia/commons/thumb/3/39/TomHanksPrincEdw031223_%2811_of_41%29_%28cropped%29.jpg/960px-TomHanksPrincEdw031223_%2811_of_41%29_%28cropped%29.jpg">
<meta property="og:image:width" content="800">
<meta property="og:image:height" content="1110">
<meta property="og:image:width" content="640">
<meta property="og:image:height" content="888">

Test case:

-BeforeAfter
WhatsApp
IMG_4898.PNG (1×750 px, 416 KB)
IMG_4899.PNG (1×750 px, 658 KB) IMG_4900.PNG (1×750 px, 536 KB)
AppleScreenshot 5.png (1×972 px, 975 KB)Screenshot 6.png (1×977 px, 1022 KB)
Discord
Screenshot 1.png (794×1 px, 498 KB)
Screenshot 2.png (844×1 px, 324 KB)
Screenshot 3.png (783×1 px, 494 KB)
Screenshot 4.png (879×1 px, 327 KB)

I included the URL of the image in the Discord screenshot, to show that the tall image is now contained to 1200px, thus selecting 675x1200px (bucket 960x1706px) instead of 1200x2132px

Krinkle assigned this task to thiemowmde.

Test wiki on Patch demo by Simon04 using patch(es) linked to this task was deleted:

https://c6a1e088d6.catalyst.wmcloud.org/w/

Edtadros subscribed.

Test Result - Prod

Status: ✅ PASS
Environment: enwiki
OS: macOS Sequoia 15.5
Browser: Chrome Canary (latest as of test date)
Device: MS
Emulated Device: NA

Test Case 1: Wikipedia article page has single og:image tag

  1. Open https://en.wikipedia.org/wiki/Tom_Hanks.
  2. Inspect page source or use DevTools Elements panel.
  3. Search for <meta property="og:image".
  4. AC1: Exactly one og:image tag is present.
  5. AC2: No duplicate og:image tags exist for different resolutions.

screenshot 118.png (1×658 px, 426 KB)

Test Case 2: Wikidata entity page has single og:image tag

  1. Open https://www.wikidata.org/wiki/Q2263.
  2. Inspect page source or use DevTools Elements panel.
  3. Search for <meta property="og:image".
  4. AC3: Exactly one og:image tag is present.
  5. AC4: No duplicate og:image tags exist for different resolutions.

screenshot 119.png (1×657 px, 202 KB)