I know that an SVG image is scalable (as its name states), so doesn't really need to be processed to be resized, as said in #3109170: Image style not applied.
I also know that some toolkits still process those image files (simply change default size in metadata, I guess): #3076311: Use image style when configured toolkit supports SVG.
But still, with the standard GD toolkit, there may be cases where we display a styled image field and don't know if the value will be an SVG, JPG,... In that case, it would be nice to be able to take the dimensions of the image style defined in the formatter settings to display the SVG image, instead of having to specify the SVG dimensions manually (what if image style dimensions change afterwards,...).
This can be done easily with HTML width and height attributes.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | svg_image-3126330-4-image_style_dimensions.patch | 1.99 KB | saurabhpandit26 |
Issue fork svg_image-3126330
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
gaëlgHere's a patch.
Comment #3
gaëlgWhoops, I forgot a little fix.
Comment #6
watergate commentedThe patch provided in #3126330-3: Apply image style dimensions with HTML attributes didn't apply anymore to the latest version, so I've updated the code and created a merge request.
Comment #7
gaëlgI tested and confirm that the merge request successfully adds width and height HTML attributes to img tags with an SVG rendered using the default image formatter with an image style applied.
Comment #8
clemorphySame as GaëlG.
MR from #5 tested and confirmed to work.
Waiting for this to be available in the next stable release.
Meanwhile is it possible to have a patch?
Comment #9
watergate commented@clemorphy, thanks for testing (and GaëlG, but you wrote the initial code). You can download a plain diff from the merge request. See the plain diff link under the issue fork list at the top of this page (left beside the green "MR !25 mergeable"). For additional information, see https://www.drupal.org/docs/develop/git/using-gitlab-to-contribute-to-dr...
Comment #10
saurabhpandit26 commentedRe-rolling the patch for latest version.
Comment #11
gaëlgI made a new branch which also contains the fix from #3257729: Formatters shouldn't repeat core code, because I needed both fixes:
https://git.drupalcode.org/issue/svg_image-3126330/-/commits/3257729-312...
The code for this issue changes quite a lot when #3257729: Formatters shouldn't repeat core code is applied.
On this branch, I also added support for responsive images. I guess my branch could become the one for an up-to-date merge request if #3257729: Formatters shouldn't repeat core code lands before this one.
I manually tested locally and it seems to work well on my use case but I did not carefully tested all the possible usages.
Comment #13
mably commentedComment #14
mably commentedLooks like I have merged it too quickly.
Styling doesn't seem to work on my side.
widthandheightseem to be alwaysNULLhere...Aren't we supposed to extract the size from the SVG file itself as it is done in the widget?
@gaëlg an idea?
Comment #15
mably commentedComment #16
mably commented@gaëlg this code seems to work, could we switch to it?
Or may be the MR code is trying to do something different that I am missing?
Without any feedback in the coming hours, I will merge MR 40 to rollback MR 25.
Comment #18
gaëlgMR40 looks good to me. If it works, it should be committed.
Comment #20
mably commented