Use viewbox if width and height are not present in svg. Fixes #76

This commit is contained in:
Stephen Sykes 2017-02-23 21:35:14 +02:00
parent 406c2a5734
commit 0adc60812c
3 changed files with 12 additions and 2 deletions

View File

@ -706,6 +706,10 @@ class FastImage
[@width, @width / @ratio]
elsif @height && @ratio
[@height * @ratio, @height]
elsif @viewbox_width && @viewbox_height
[@viewbox_width, @viewbox_height]
else
nil
end
end
@ -728,7 +732,11 @@ class FastImage
return if @width
elsif attr_name.join =~ /viewbox/i
values = attr_value.split(/\s/)
@ratio = values[2].to_f / values[3].to_f
if values[2].to_f > 0 && values[3].to_f > 0
@ratio = values[2].to_f / values[3].to_f
@viewbox_width = values[2].to_i
@viewbox_height = values[3].to_i
end
end
when /\w/
attr_name << char

1
test/fixtures/test3.svg vendored Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -34,7 +34,8 @@ GoodFixtures = {
"webp_vp8.webp" => [:webp, [550, 368]],
"test.svg" => [:svg, [200, 300]],
"test_partial_viewport.svg" => [:svg, [860, 400]],
"test2.svg" => [:svg, [366, 271]]
"test2.svg" => [:svg, [366, 271]],
"test3.svg" => [:svg, [255, 48]]
}
BadFixtures = [