FIX - use ImageMagick to determine size of svg images (#12230)

SVG files can have dimensions expressed in inches, centimeters, etc., which may lead to the dimensions being misinterpreted (e.g. “8in” ends up as 8 pixels).

If the file type is `svg`, ask ImageMagick to work out what size the SVG file should be rendered on screen.

NOTE: The `pencil.svg` file was obtained from https://freesvg.org/1534028868, which has placed the file in to the public domain.
This commit is contained in:
jbrw
2021-03-01 11:44:00 -05:00
committed by GitHub
parent 6809cccd88
commit a9b6f4d829
4 changed files with 272 additions and 3 deletions

View File

@ -535,6 +535,20 @@ RSpec.describe UploadCreator do
end
end
describe "svg sizing" do
let(:svg_filename) { "pencil.svg" }
let(:svg_file) { file_from_fixtures(svg_filename) }
it "should handle units in width and height" do
upload = UploadCreator.new(svg_file, svg_filename,
force_optimize: true,
).create_for(user.id)
expect(upload.width).to be > 100
expect(upload.height).to be > 100
end
end
describe '#should_downsize?' do
context "GIF image" do
let(:gif_file) { file_from_fixtures("animated.gif") }