Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ public function fix_admin_preview( $response, $attachment, $meta ) {
}

/**
* Filters the image src result.
* If the image size doesn't exist, set a default size of 100 for width and height
* Filters the image size results.
*
* @param array|false $image Either array with src, width & height, icon src, or false.
* @param int $attachment_id Image attachment ID.
Expand All @@ -270,13 +269,8 @@ public function fix_admin_preview( $response, $attachment, $meta ) {
*/
public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
if ( get_post_mime_type( $attachment_id ) === 'image/svg+xml' ) {
if ( empty( $image[1] ) ) {
$image[1] = 100;
}

if ( empty( $image[2] ) ) {
$image[2] = 100;
}
$image['1'] = false;
$image['2'] = false;
}

return $image;
Expand Down Expand Up @@ -464,7 +458,7 @@ protected function svg_dimensions( $svg ) {
$height = 0;
if ( $svg ) {
$attributes = $svg->attributes();
if ( isset( $attributes->width, $attributes->height ) && is_numeric( (float)$attributes->width ) && is_numeric( (float)$attributes->height ) ) {
if ( isset( $attributes->width, $attributes->height ) && is_numeric( $attributes->width ) && is_numeric( $attributes->height ) ) {
$width = floatval( $attributes->width );
$height = floatval( $attributes->height );
} elseif ( isset( $attributes->viewBox ) ) {
Expand Down