jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Allow Letterbox on height AND width at the same time

Open NicktheGeek opened this issue 7 years ago • 11 comments

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.

NicktheGeek avatar Feb 05 '19 19:02 NicktheGeek

Related AMP issue: https://github.com/ampproject/amp-wp/issues/1812

jjeaton avatar Feb 05 '19 19:02 jjeaton

@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 avatar Feb 05 '19 21:02 jeherve

@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,
	);
}

NicktheGeek avatar Feb 05 '19 21:02 NicktheGeek

It is much easier to use the resize functionality to achieve a better end result, resize={w},{h}

darthhexx avatar Feb 06 '19 02:02 darthhexx

@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.

NicktheGeek avatar Feb 06 '19 02:02 NicktheGeek

88663-zd-wordpressvip

cafenoirdesign avatar Feb 06 '19 12:02 cafenoirdesign

@darthhexx I just tried using resize and it does not upscale the image as needed.

NicktheGeek avatar Feb 06 '19 14:02 NicktheGeek

Are you using a Photon URL, could you post it here?

darthhexx avatar Feb 06 '19 14:02 darthhexx

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/

rijoio avatar Apr 11 '19 10:04 rijoio

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.

stale[bot] avatar Oct 08 '19 10:10 stale[bot]

This should have been fixed in #12821

jeherve avatar Jan 20 '20 14:01 jeherve