Skip to content

Commit

Permalink
feat: block jetpack image optimizer from downsizing avatars.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersonrabb committed Feb 10, 2020
1 parent 955bf64 commit 59a04f1
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions newspack-theme/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,26 @@ function newspack_front_page_template( $template ) {
}
add_filter( 'frontpage_template', 'newspack_front_page_template' );

/**
* Override Jetpack Image Accelerator (Photon) downsizing of avatars. If an image has a square aspect ratio and the width is between 1-120px, assume it is an avatar and block downsizing.
* https://developer.jetpack.com/hooks/jetpack_photon_override_image_downsize/
*
* @param boolean $default The default value, generally false.
* @param array $args Array of image details.
*
* @return boolean Should Photon be stopped from downsizing.
*/
function newspack_override_avatar_downsizing( $default, $args ) {
if ( is_array( $args['size'] ) && 2 === count( $args['size'] ) ) {
list( $width, $height ) = $args['size'];
if ( $width === $height && $width <= 120 & $width > 0 ) {
return true;
}
}
return $default;
}
add_filter( 'jetpack_photon_override_image_downsize', 'newspack_override_avatar_downsizing', 10, 2 );

/**
* Register meta fields:
* - Featured Image position option
Expand Down

0 comments on commit 59a04f1

Please sign in to comment.