Hi @strarsis,
Thanks for your suggestion.
I played with that a few years ago… But will take another look when I get a chance. I have been thinking about different options when it comes to how image attributes are handled.
Hi there,
I finally got a chance to spend some time on the plugin…
I believe this ticket refers to the admin not displaying the SVG thumbnails due to sizing, which is already implemented in my plugin.
Correct me if I’m wrong though.
@benbodhi: Feedback after some time:
I just encountered the issue again.
It is not just the preview in admin/backend –
all images with markup from wp_get_attachment_image(...) are affected,
so also in frontend SVG images collapse to 1px x 1px dimensions.
There is a fix in WordPress for this –
this plugin would be ideal for this (to make WordPress supporting SVGs).
Edit: When the issue has been fixed in WordPress core, the plugin could add a check for WordPress version and only apply the fix if the WordPress version is still affected.
Thanks in advance!
-
This reply was modified 8 years, 6 months ago by
strarsis.
I’m not sure I see your issue.
Are you using the latest version of my plugin and WordPress?
@benbodhi: Yes, I am using latest WordPress, WooCommerce and your plugin.
I assigned a SVG image to a WooCommerce category.
While the raster PNG images are shown correctly, the SVGs aren’t visible and only got a dimension of 1px x 1px.
I see, I’ll try and work in some support for that in the next update.
In the meantime, you can likely just use css to fill the frame.
@benbodhi:
I am using the code from the discussion on the WordPress issue tracker:
// Code from:
// https://wordpress.stackexchange.com/questions/240579/issue-with-wp-get-attachment-image-and-svg-file-type
// https://core.trac.ww.wp.xz.cn/ticket/26256
/**
* Removes the width and height attributes of <img /> tags for SVG
*
* Without this filter, the width and height are set to "1" since
* WordPress core can't seem to figure out an SVG file's dimensions.
*
* For SVG:s, returns an array with file url, width and height set
* to null, and false for 'is_intermediate'.
*
* @wp-hook image_downsize
* @param mixed $out Value to be filtered
* @param int $id Attachment ID for image.
* @return bool|array False if not in admin or not SVG. Array otherwise.
*/
function wpse240579_fix_svg_size_attributes( $out, $id ) {
$image_url = wp_get_attachment_url( $id );
$file_ext = pathinfo( $image_url, PATHINFO_EXTENSION );
if ( is_admin() || 'svg' !== $file_ext ) {
return false;
}
return array( $image_url, null, null, false );
}
add_filter( 'image_downsize', 'wpse240579_fix_svg_size_attributes', 10, 2 );
-
This reply was modified 8 years, 6 months ago by
strarsis.
Thanks for the update.
I will test when I’m working on the plugin next.
I thought it worked already for WooCommerce categories and this fix looks very similar to what I had to implement to avoid this issue in the media library thumbnails.
Thanks for your support.