Skip to content

Commit

Permalink
perf: improve type casting on size constrain
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Jan 21, 2019
1 parent 6c2401f commit 589b046
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions inc/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ public function inline_bootstrap_script() {
var s = d.createElement("script");
var v = ("IntersectionObserver" in w) ? "_no_poly" : "";
s.async = true;
s.src = "%s/v2/latest/optimole_lib" + v + "%s.js";
s.src = "%s/optimole_lib" + v + "%s.js";
b.appendChild(s);
}(window, document));
document.addEventListener( "DOMContentLoaded", function() { document.body.className = document.body.className.replace("optimole-no-script",""); } );
</script>',
esc_url( $domain ),
esc_url( 'https://s3.amazonaws.com/optimole-js-lib/tags/v2' ),
$min
);
echo $output;
Expand Down
11 changes: 9 additions & 2 deletions inc/url_replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,15 @@ public function build_image_url(
list( $args['width'], $args['height'] ) = $this->parse_dimensions_from_filename( $url );
$url = $new_url;
}

list( $args['width'], $args['height'] ) = wp_constrain_dimensions( (int) $args['width'], (int) $args['height'], $this->max_width, $this->max_height );
$args['width'] = (int) $args['width'];
$args['height'] = (int) $args['height'];
if ( $args['width'] > 0 && $args['height'] > 0 ) {
list( $args['width'], $args['height'] ) = wp_constrain_dimensions( $args['width'], $args['height'], $this->max_width, $this->max_height );
} elseif ( $args['width'] > 0 ) {
$args['width'] = $args['width'] > $this->max_width ? $this->max_width : $args['width'];
} elseif ( $args['height'] > 0 ) {
$args['height'] = $args['height'] > $this->max_height ? $this->max_height : $args['height'];
}

return ( new Optml_Image( $url, $args ) )->get_url( $this->is_allowed_site );
}
Expand Down

0 comments on commit 589b046

Please sign in to comment.