Allow Letterbox on height AND width at the same time
Is your feature request related to a problem? Please describe.
Google recently changed requirements for the AMP image size. This has resulted in a significant number of warnings, mostly for older content. A client I work with is using Jetpack with photon so we had hoped to use the letterbox functionality in order to make older images at least 1200px wide. This was done with a filter in the AMP WP plugin and the output is working as expected but the images are not being letterboxed.
After some research it seems that letterbox will only apply to the width or height, not both. I'm applying a % multiplier to the height so the end result has the same aspect ratio as the original image. This is because in addition to the width, the image also has a theoretical minimum pixel count and being able to increase the height should make it more likely to meet the minimum pixel count should Google ever enforce that.
Describe the solution you'd like
Ideally the letterbox should be applied to the height and width.
Describe alternatives you've considered
The only alternative is to apply to only the width, which will likely be enough for now but risks issues down the road.
Related AMP issue: https://github.com/ampproject/amp-wp/issues/1812
@NicktheGeek Would you mind sharing the snippet you use today so we can see what Photon parameters you change?
Thank you!
cc @darthhexx for some insight.
@jeherve here is the current code
$image_id = get_post_thumbnail_id( get_the_ID() );
$image_meta = wp_get_attachment_image_src( $image_id, 'full' );
if ( isset( $image_meta[1] ) && 1200 > (int) $image_meta[1] ) {
$width = 1200;
$height = intval( ( $image_meta[2] / $image_meta[1] ) * 1200 );
$image_url = add_query_arg( array(
'lb' => $width . ',' . $height,
), $image_meta[0] );
$metadata['image'] = array(
'@type' => 'ImageObject',
'url' => $image_url,
'width' => $width,
'height' => $height,
);
}
It is much easier to use the resize functionality to achieve a better end result, resize={w},{h}
@darthhexx does the resize allow you to make the image larger than the original image and is there an upper range on that?
For example a 600x400 image would need to rescale to 1200x800. This is actually very close to the most common resizing based on what I’ve seen so far.
88663-zd-wordpressvip
@darthhexx I just tried using resize and it does not upscale the image as needed.
Are you using a Photon URL, could you post it here?
Not sure if this is related but having the same issue. In order to use the Discover from Google, images need to be above 1200px (with). Right now they are being resized to less than that. Here an example using photon:
https://ppc.land/wpp-to-sell-kantar-in-an-auction-this-month/amp/
This issue has been marked as stale. This happened because:
- It has been inactive in the past 6 months.
- It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.
No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.
This should have been fixed in #12821