diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2017-12-12 20:29:44 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2017-12-12 20:29:55 -0500 |
commit | 73ce9c10188ce4f5014c97ad4c0f8c9f69410113 (patch) | |
tree | ac0b7b2f7cb14a145e2308d705033f89cebc736d /plugins/jetpack/class.photon.php | |
parent | Update wordpress-mobile-pack 3.2 (diff) | |
download | blogs-gentoo-73ce9c10188ce4f5014c97ad4c0f8c9f69410113.tar.gz blogs-gentoo-73ce9c10188ce4f5014c97ad4c0f8c9f69410113.tar.bz2 blogs-gentoo-73ce9c10188ce4f5014c97ad4c0f8c9f69410113.zip |
Update jetpack 5.6
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'plugins/jetpack/class.photon.php')
-rw-r--r-- | plugins/jetpack/class.photon.php | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/plugins/jetpack/class.photon.php b/plugins/jetpack/class.photon.php index 072e339d..636217d7 100644 --- a/plugins/jetpack/class.photon.php +++ b/plugins/jetpack/class.photon.php @@ -344,8 +344,36 @@ class Jetpack_Photon { unset( $placeholder_src ); } - // Remove the width and height arguments from the tag to prevent distortion - $new_tag = preg_replace( '#(?<=\s)(width|height)=["|\']?[\d%]+["|\']?\s?#i', '', $new_tag ); + // If we are not transforming the image with resize, fit, or letterbox (lb), then we should remove + // the width and height arguments from the image to prevent distortion. Even if $args['w'] and $args['h'] + // are present, Photon does not crop to those dimensions. Instead, it appears to favor height. + // + // If we are transforming the image via one of those methods, let's update the width and height attributes. + if ( empty( $args['resize'] ) && empty( $args['fit'] ) && empty( $args['lb'] ) ) { + $new_tag = preg_replace( '#(?<=\s)(width|height)=["|\']?[\d%]+["|\']?\s?#i', '', $new_tag ); + } else { + $resize_args = isset( $args['resize'] ) ? $args['resize'] : false; + if ( false == $resize_args ) { + $resize_args = ( ! $resize_args && isset( $args['fit'] ) ) + ? $args['fit'] + : false; + } + if ( false == $resize_args ) { + $resize_args = ( ! $resize_args && isset( $args['lb'] ) ) + ? $args['lb'] + : false; + } + + $resize_args = array_map( 'trim', explode( ',', $resize_args ) ); + + // (?<=\s) - Ensure width or height attribute is preceded by a space + // (width=["|\']?) - Matches, and captures, width=, width=", or width=' + // [\d%]+ - Matches 1 or more digits + // (["|\']?) - Matches, and captures, ", ', or empty string + // \s - Ensures there's a space after the attribute + $new_tag = preg_replace( '#(?<=\s)(width=["|\']?)[\d%]+(["|\']?)\s?#i', sprintf( '${1}%d${2} ', $resize_args[0] ), $new_tag ); + $new_tag = preg_replace( '#(?<=\s)(height=["|\']?)[\d%]+(["|\']?)\s?#i', sprintf( '${1}%d${2} ', $resize_args[1] ), $new_tag ); + } // Tag an image for dimension checking $new_tag = preg_replace( '#(\s?/)?>(\s*</a>)?$#i', ' data-recalc-dims="1"\1>\2', $new_tag ); |