Skip to content

Commit

Permalink
Merge pull request #19 from 10up/fix/15-image-dimentions
Browse files Browse the repository at this point in the history
Bug fixes relating to image dimensions
  • Loading branch information
jeffpaul authored Jan 25, 2022
2 parents c0c2525 + 10bb4d6 commit 3115e4f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function skip_svg_regeneration( $metadata, $attachment_id ) {
$svg_path = get_attached_file( $attachment_id );
$upload_dir = wp_upload_dir();
// get the path relative to /uploads/ - found no better way:
$relative_path = str_replace( $upload_dir['basedir'], '', $svg_path );
$relative_path = str_replace( trailingslashit( $upload_dir['basedir'] ), '', $svg_path );
$filename = basename( $svg_path );

$dimensions = $this->svg_dimensions( $svg_path );
Expand Down Expand Up @@ -426,7 +426,7 @@ protected function svg_dimensions( $svg ) {
$height = 0;
if ( $svg ) {
$attributes = $svg->attributes();
if ( isset( $attributes->width, $attributes->height ) && is_numeric( $attributes->width ) && is_numeric( $attributes->height ) ) {
if ( isset( $attributes->width, $attributes->height ) && is_numeric( (float)$attributes->width ) && is_numeric( (float)$attributes->height ) ) {
$width = floatval( $attributes->width );
$height = floatval( $attributes->height );
} elseif ( isset( $attributes->viewBox ) ) {
Expand Down Expand Up @@ -481,7 +481,6 @@ public function fix_direct_image_output( $attr, $attachment, $size = 'thumbnail'

return $attr;
}

}
}

Expand Down

0 comments on commit 3115e4f

Please sign in to comment.