mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-10-06 00:02:01 -04:00
Use viewbox if width and height are not present in svg. Fixes #76
This commit is contained in:
parent
406c2a5734
commit
0adc60812c
@ -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
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 |
@ -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 = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user