Wikipedia:Reference desk/Archives/Computing/2015 November 23

= November 23 =

Convert SVG to JPEG or other format
Is there a good way to convert an SVG file to a format such as JPEG and retain the quality? I've done this many times by doing a screenshot, but that loses a lot of quality. I've just tried four things I found on the internet and they all give very poor results. What can I do that will retain quality? Bubba73 You talkin' to me? 00:37, 23 November 2015 (UTC)
 * SVG is for vector graphics, and often has simple lines and hard transitions. This is not good for JPEG - you might want to go with something like PNG. For most of these jobs, ImageMagick is very good. I've never used it with SVG (afair), but it s among the formats listed as supported. Just install it and type "convert myimage.svg myimage.png" and it will do its magic. --Stephan Schulz (talk) 01:14, 23 November 2015 (UTC)


 * Thanks. I just tried that on Windows 10 and it was running, but then gave an error message: "ImageMagick Studio library and utility programs has stopped working.  A problem caused the program to stop working correctly..." Bubba73 You talkin' to me? 01:56, 23 November 2015 (UTC)


 * Well, despite the error message, it did actually convert it to a PNG, but the resolution is poor. Bubba73 You talkin' to me? 01:58, 23 November 2015 (UTC)


 * Does ImageMagick have a parameter that sets the resolution during the conversion ? StuRat (talk) 02:09, 23 November 2015 (UTC)


 * I don't know about Windows, but yes, ImageMagick convert does have about a zillion options, listed at http://www.imagemagick.org/script/convert.php. Try, and maybe throw -antialias in there. Careful - as far as I know, the order of files and options is significant, so you want to set the density before the file name ("sample at that density"). --Stephan Schulz (talk) 07:44, 23 November 2015 (UTC)
 * Open the svg file in Inkscape and use "save as". Select "Cairo .PNG" or "Extended metafile .EMF". Both can be opened in Windows paint (Windows 7). Then save as jpeg. --NorwegianBluetalk 07:22, 23 November 2015 (UTC)
 * It would be better to keep it as a PNG unless you have to use JPEG. JPEG is designed for photographs (the P of the acronym) and does a terrible job on line art. -- BenRG (talk) 07:33, 23 November 2015 (UTC)
 * Yes, I'll link Vector graphics, raster graphics and Rasterisation for good measure.


 * You absolutely cannot convert SVG to JPEG, PNG, BMP, GIF or any other raster format without losing some quality - period. In SVG, a circle has an origin and a radius - and that's about it.  In a raster format, you have an explicit list of pixels stored somehow.  The centers of those pixels are at integer coordinates - and that can't ever represent a circle perfectly because PI isn't a rational number.


 * So, any effort to convert SVG (or any other vector format) into JPEG (or any other raster format) is 100% guaranteed to lose precision. The real question here is how much precision you actually need - once you know that, you can do the conversion and get a result that's precise enough to at least meet the precision that you need.  If you're going to display your SVG-converted-to-JPEG image full-screen on a monitor that's 1900x1200 pixels, then you're going to need an image that's at least that resolution.  If it's only going to be displayed on an iWatch then a mere 400x400 would be overkill. But if you then expect to be able to zoom that image without it getting blocky - then you'll need more resolution. If you're going to send your image off to a print shop and have them make a 50 foot tall poster with pixels so small that it doesn't look blurry - then you may need 50,000 x 50,000 pixels.


 * SVG will never be blocky, no matter how big you blow it up...but since the display device you're using uses pixels (almost certainly) then the price you pay is that the image has to be re-rendered every time it's displayed.  The cost of doing that may become rather extreme if you have a very complex image.
 * SteveBaker (talk) 20:50, 23 November 2015 (UTC)


 * GIMP can read SVG and export it as JPG. JPG can not be scaled. When opening the SVG You will be prompted for a resolution or size in pixels for the picture to be rendered. A later rescaling up the picture will decrease picture quality. -- Hans Haase (有问题吗) 23:16, 24 November 2015 (UTC)

OK, I'm going to try some of these other suggestions. When I used ImageMagick without any parameters, the results were much poorer than using the browser to blow up the SVG as large as it could, take a screen shot, and import it into photoshop. And, you are right, I don't need it as a JPEG - just something that I can crop out pieces in Photoshop. Bubba73 You talkin' to me? 06:10, 25 November 2015 (UTC)
 * On a Mac, at least Google Chrome allows you to print an SVG image to PDF (via the print dialog -> open PDF in preview), and Preview can crop and convert the image to many different formats. The PDF is still vectorised, i.e. you don't lose any quality in that step. I think modern Windows will also support "Print to file" or something similar. --Stephan Schulz (talk) 10:01, 25 November 2015 (UTC)