jekyll-favicon icon indicating copy to clipboard operation
jekyll-favicon copied to clipboard

SVG not scaled when it includes 'width' and 'height' attributes

Open dgw opened this issue 1 year ago • 0 comments

Describe the bug An SVG image that has width and height attributes will not be scaled (up or down) during conversion.

I was able to bisect this down to b2e0439aee62ea49be55de1a5bca01d608421c20, when this plugin switched from scale to size.

To Reproduce Run jekyll-favicon on a site with the following minimal SVG as its favicon.svg file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   width="64"
   height="64"
   viewBox="0 0 64 64">
  <circle cx='32' cy='32' fill='red' r='15'/>
</svg>

This is based on test/fixtures/favicon.svg, but sized larger so cropping will be evident in the .ico output and with the problematic width & height attributes added.

Expected behavior Image is scaled as normal, even if it has width & height specified—especially if those dimensions match those of the viewBox.

Screenshots Source favicon.svg:

favicon.svg

Output favicon.ico:

image

Environment:

  • OS name and version: Ubuntu 22.04 (both in GitHub Actions and in WSL1 locally)
  • Ruby manager name and version (if present): rvm 1.29.12
  • Ruby version: 3.2.2
  • Bundler version: 2.4.10
  • Jekyll version: 4.3.3
  • Jekyll Favicon version: 1.1.0

Additional context:

The same test SVG with just those two attributes removed works properly:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns="http://www.w3.org/2000/svg"
   version="1.1"
   viewBox="0 0 64 64">
  <circle cx='32' cy='32' fill='red' r='15'/>
</svg>

Note, while I reported this against Ruby 3.2.2, Jekyll 4.3.3, etc. I did go all the way back to Ruby 2.7.8 + Jekyll 4.2.2 while bisecting to track down the commit that changed this behavior. (rvm was very helpful for that!) Ruby 3.x vs. 2.x seems not to affect this problem at all.

dgw avatar Jan 09 '24 23:01 dgw