mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-30 19:16:01 +00:00
Output multiple og:image with widths 1200/800/640
Multiple images are supported according to https://ogp.me/#array. Facebook suggest an image with at least 1080px. WhatsApp ignores images >300px. Bug: T282065 Change-Id: Ibc18df03fbd6f4ec9f4970331e1b5bf930710816
This commit is contained in:
parent
b28c4b85b8
commit
d3f9a011fd
|
@ -258,13 +258,19 @@ class PageImages {
|
|||
return;
|
||||
}
|
||||
|
||||
// See https://developers.facebook.com/docs/sharing/best-practices?locale=en_US#tags
|
||||
$thumb = $imageFile->transform( [ 'width' => 1200 ] );
|
||||
if ( !$thumb ) {
|
||||
return;
|
||||
// Open Graph protocol -- https://ogp.me/
|
||||
// Multiple images are supported according to https://ogp.me/#array
|
||||
// See https://developers.facebook.com/docs/sharing/best-practices?locale=en_US#images
|
||||
// See T282065: WhatsApp expects an image <300kB
|
||||
foreach ( [ 1200, 800, 640 ] as $width ) {
|
||||
$thumb = $imageFile->transform( [ 'width' => $width ] );
|
||||
if ( !$thumb ) {
|
||||
continue;
|
||||
}
|
||||
$out->addMeta( 'og:image', wfExpandUrl( $thumb->getUrl(), PROTO_CANONICAL ) );
|
||||
$out->addMeta( 'og:image:width', strval( $thumb->getWidth() ) );
|
||||
$out->addMeta( 'og:image:height', strval( $thumb->getHeight() ) );
|
||||
}
|
||||
|
||||
$out->addMeta( 'og:image', wfExpandUrl( $thumb->getUrl(), PROTO_CANONICAL ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue