Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we keep proper height and width settings for SVGs, unless those values don't exist #23

Merged
merged 2 commits into from
Feb 15, 2022
Merged
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
13 changes: 9 additions & 4 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public function fix_admin_preview( $response, $attachment, $meta ) {

/**
* Filters the image src result.
* Here we're gonna spoof the image size and set it to 100 width and height
* If the image size doesn't exist, set a default size of 100 for width and height
*
* @param array|false $image Either array with src, width & height, icon src, or false.
* @param int $attachment_id Image attachment ID.
Expand All @@ -236,9 +236,14 @@ public function fix_admin_preview( $response, $attachment, $meta ) {
* @return array
*/
public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
if ( get_post_mime_type( $attachment_id ) == 'image/svg+xml' ) {
$image['1'] = false;
$image['2'] = false;
if ( get_post_mime_type( $attachment_id ) === 'image/svg+xml' ) {
if ( empty( $image[1] ) ) {
$image[1] = 100;
}

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

return $image;
Expand Down