Skip to content

Commit

Permalink
Built release for 0.3.14. For a full change log look at the notes wit…
Browse files Browse the repository at this point in the history
…hin the original/0.3.14 release.
  • Loading branch information
github-actions[bot] committed Nov 22, 2022
1 parent bbdd8ac commit 72472c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"owner":"humanmade","repo":"smart-media","sha":"d7c3d6c6f6a757c220de4b7a766fca55ead55d83","ref":"refs/tags/0.3.13","tagName":"0.3.13","branch":"gh-actions","tags":["0.3.13"],"updated_at":"2021-12-14T22:24:08.799Z"}
{"owner":"humanmade","repo":"smart-media","sha":"991a36edd4f9e3fa025067f0649974a42b18d0ce","ref":"refs/tags/0.3.14","tagName":"0.3.14","branch":"gh-actions","tags":["0.3.14"],"updated_at":"2022-11-22T15:10:40.418Z"}
14 changes: 11 additions & 3 deletions inc/cropper/namespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -1161,12 +1161,16 @@ function image_srcset( array $sources, array $size_array, string $image_src, arr

list( $width, $height ) = array_map( 'absint', $size_array );

// Ensure this is a tachyon image, not always the case when parsing from post content.
// Ensure this is _not_ a tachyon image, not always the case when parsing from post content.
if ( strpos( $image_src, TACHYON_URL ) === false ) {
// If the aspect ratio requested matches a custom crop size, pull that
// crop (in case there's a user custom crop). Otherwise just use the
// given dimensions.
$size = nearest_defined_crop_size( $width / $height ) ?: [ $width, $height ];
$size = [ $width, $height ];
// Avoid errors if either dimension is zero, natural aspect ratio requested so no crop.
if ( $width && $height ) {
$size = nearest_defined_crop_size( $width / $height ) ?: $size;
}

// Get the tachyon URL for this image size.
$image_src = wp_get_attachment_image_url( $attachment_id, $size );
Expand Down Expand Up @@ -1225,6 +1229,10 @@ function image_srcset( array $sources, array $size_array, string $image_src, arr
* @return string|null Closest defined image size to that ratio; null if none match.
*/
function nearest_defined_crop_size( $ratio ) {
// Get only the custom image sizes that are croppable.
$croppable_sizes = array_filter( wp_get_additional_image_sizes(), function ( $size ) {
return absint( $size['width'] ) && absint( $size['height'] );
} );
/*
* Compare each of the theme crops to the ratio in question. Returns a
* sort-of difference where 0 is identical. Not mathematically meaningful
Expand All @@ -1242,7 +1250,7 @@ function( $crop_data ) use ( $ratio ) {
return abs( $crop_ratio / $ratio - 1 );
},
// ... of all the custom image sizes defined.
wp_get_additional_image_sizes()
$croppable_sizes
);
// Sort the differences from most to least similar.
asort( $difference_from_theme_crop_ratios, SORT_NUMERIC );
Expand Down

0 comments on commit 72472c8

Please sign in to comment.