Having same problem as described at https://www.imagemagick.org/discourse-server/viewtopic.php?t=11746.
I built GraphicsMagick from source in GraphicsMagick-1.3.26-windows-source.7z using Visual Studio 2015.
The following command does not give the expected results:
gm convert -units PixelsPerInch -density 100 TestSimple.svg -density 100 TestSimple.png
The SVG file (attached) specifies:
width="6in" height="4in"
viewBox="0in 0in 6in 4in"
So at 100 dpi the output image should be 600 x 400 pixels, but the actual output image is 833 x 556. I found the problem using the debugger. File svg.c, line 2911 has the following code:
IdentityAffine(&svg_info.affine);
svg_info.affine.sx=
image->x_resolution == 0.0 ? 1.0 : image->x_resolution/72.0;
svg_info.affine.sy=
image->y_resolution == 0.0 ? 1.0 : image->y_resolution/72.0;
svg_info.scale[0]=ExpandAffine(&svg_info.affine);
"svg_info.scale[0]" gets set to 1.38888, which is 100/72, the ratio of the requested dpi to the "baseline" dpi of 72. When the svg input file is parsed and the "width" specification is encountered, the following code gets executed (there is similar code for the "height"):
if (LocaleCompare(keyword,"width") == 0)
{
svg_info->bounds.width=
GetUserSpaceCoordinateValue(svg_info,1,value,MagickTrue);
break;
}
The value "6in", indicating 6 inches, is converted to pixels in function GetUserSpaceCoordinateValue() at line 252 as follows:
if (LocaleNCompare(token,"in",2) == 0)
return(72.0svg_info->scale[0]value);
This code returns the expected value of 100 pixels/inch * 6 inches = 600 pixels. Later, at line 2265 we see:
page.width=(unsigned long) svg_info->bounds.width;
page.height=(unsigned long) svg_info->bounds.height;
"page.width" is set to 600. Finally at line 2288 we get to the root of the problem:
if (svg_info->affine.sx != 1.0)
page.width=(unsigned long)
ceil(ExpandAffine(&svg_info->affine)*page.width-0.5);
if (svg_info->affine.sy != 0.0)
page.height=(unsigned long)
ceil(ExpandAffine(&svg_info->affine)*page.height-0.5);
The values "page.width" and "page.height" are scaled AGAIN by a factor of 100/72 as returned by ExpandAffine(). This will happen for any width or height value with units of "cm", "in", "mm", "pc", or "pt".
So to summarize, the scale factor computed by "svg_info.scale[0] = ExpandAffine(...)" gets applied to the width and height by GetUserSpaceCoordinateValue(), but then that same scale factor computed by ExpandAffine() is incorrectly applied AGAIN to the width and height.
Hope this helps. Please fix.
Fix pushed to repository on 1/22/18.