tachyon-plugin icon indicating copy to clipboard operation
tachyon-plugin copied to clipboard

Create custom `srcset` attributes based on source image crop.

Open peterwilsoncc opened this issue 5 years ago • 2 comments

Currently the Tachyon Plugin builds the srcset attribute by replacing the sources WP core builds with Tachyon URLs. If the inserted image's aspect ratio doesn't match the ratio of any of the core image sizes (small, medium, etc) or an image size added by add_image_size() then the srcset is empty.

As Tachyon can recreate the source crop at any size up to that of the original image, a series of sensible defaults can be used to generate the srcset. These sensible defaults can be based on common device screen resolutions.

srcset_widths = [
  640, // 320@2x
  960, // 480@2x
  $content_width * 2,
  // etc
];

There are a few conditions in the core function wp_calculate_image_srcset() that we'd need to ensure we pass by applying a custom filter to wp_calculate_image_srcset_meta.

https://github.com/WordPress/wordpress-develop/blob/fd5ba80c5c3d9cf62348567073945e246285fbca/src/wp-includes/media.php#L1046-L1219

peterwilsoncc avatar Oct 02 '18 23:10 peterwilsoncc

Related https://core.trac.wordpress.org/ticket/40370

peterwilsoncc avatar Oct 13 '18 00:10 peterwilsoncc

We have an implementation of this in the smart media plugin now, could look at porting that across.

roborourke avatar Feb 19 '20 11:02 roborourke