0

This question may have been answered in multiple websites. However, I am having issues getting it to work correctly.

My goal is to convert an SVG file to BMP using command line. Below is the content of a simple SVG file. Note the resolution must be 912x1140px. Thus the resulting BMP file must be 912x1140px as defined in the SVG.

<?xml version="1.0" encoding="utf-8" ?>
<svg baseProfile="full" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xlink="http://www.w3.org/1999/xlink" width="912px" height="1140px" preserveAspectRatio="none" viewBox="0,0,9.855,6.1614"><defs />
<rect fill="#FFF" height="100%" width="100%" x="0" y="0" />
<rect x="4" y="2.5" width="1.0" height="1.0" fill="#000" />
</svg>

When I use GIMP using GUI, the resulting BMP file is correct as expected having a size of 912x1140px. The size of the file is ~3.96MB. However I must use the GUI to open my SVG file and manually convert it to BMP. I prefer to use command line because I have a batch of SVG files I want to convert.

When I use ImageMagick to convert, the resulting BMP file gets resized to 855x1069px instead of staying at 912x1140px. The resulting BMP file ~3.48MB: convert myfile.svg myfile.bmp

When I use rsvg-convert, the resulting BMP file is correct 912x1140 but its around 7KB. I am unsure if rsvg-convert even supports BMP format because according to the docs, BMP is not listed as the support format. Thus this leads me to question if the convert BMP file is even correct. rsvg-convert -o myfile.bmp myfile.svg

When I use command line Inkscape, the resulting BMP file is correct resolution of 912x1140, but size is around 6.51KB. I am unsure if this is correct since the BMP file generated using GIMP results in a file size of 3.96MB. Secondly, Inkscape GUI doens't have any options to export to BMP. In addition, it defaults to 32 bits. I want it to be 24 bit depth. inkscape -z myfile.svg -e myfile.bmp

Zythyr
  • 1,142
  • 4
  • 20
  • 33
  • set the density to 96 to ensure it is correct. You can use Imagmagick to do the conversion to BMP. Best to use Inkscape with Imagemagick rather than its own MSVG or RSVG renderers. `convert -density 96 image.svg image.bmp` Or, to get higher quality, increase the density by 4x and then add -resize 25% after image.svg. – fmw42 Oct 30 '19 at 05:04
  • Additionally, Inkscape doesn't save as bmp. I assume the file is actually a PNG when generated with Inkscape. – Moini Oct 30 '19 at 21:44
  • 1) @fmw42 Why does ImageMagick not use density of 96 by default? By default why does it convert the original SVG to a PNG/BMP with a a weird resolution of 855x1069px instead of the original 912x1140px? Also how did you know to use density of 96 and not some other number? 2) According to https://superuser.com/a/386066/607501, PNG is a lossless format. Is converting a PNG to BMP a valid approach instead of SVG to BMP? Would the BMP that is converted from a PNG still a "highest quality" format? – Zythyr Nov 03 '19 at 20:11
  • `@Zythyr` For SVG files, ImageMagick used other tools -- RSVG or Inkscape. It tries to follow the CSS guides for default density for SVG file rendering. The density used for the SVG determines the output file size of the raster image such as PNG. CSS says 96 dpi. PNG requires densities in dpc (dots per centimeter) and so converts dpi to dpc. Thus the listed density might appear different due to the units. PNG to BMP is raster to raster. It does not require a density to rasterize. Default viewing densities for raster images are 72 dpi unless specified otherwise when creating the raster image. – fmw42 Nov 03 '19 at 20:15
  • Quality is different from density. Quality has to do with compression for PNG and JPG, for example. Density has to do with rasterizing a vector image or printing a raster image. – fmw42 Nov 03 '19 at 20:15

0 Answers0