Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create custom srcset attributes based on source image crop. #34

Open
peterwilsoncc opened this issue Oct 2, 2018 · 2 comments
Open

Comments

@peterwilsoncc
Copy link
Contributor

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
Copy link
Contributor Author

@roborourke
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants