Конвертнуть *.svg в *.png с заданным размером
Посоветуйте простой способ. Можно консольную утилитку, можно гуевую.
Я эти 36 метров из реп буду пол дня тянуть. Может есть че более мелкое?
В репах ни первое, ни второе не могу найти,
Они входят в состав imagemagick
imagemagick, но мне он мне по каким-то причинам (точно не помню) не подошел. вроде бы косяки с прозрачностью.
Круто, клевый инструмент. Но у меня тут косяк вылез — серые свг конвертятся в черные пнг. Ни каких доп. параметров не указываю, ибо хочу получить такую же иконку другого формата. Но у Image Magicka логика явно другая.
crowbar
imagemagick, но мне он мне по каким-то причинам (точно не помню) не подошел. вроде бы косяки с прозрачностью.
How to convert a folder with SVG files to PNG with inkscape linux?
I have in my image folders in my WordPress installation a few thousands of SVG files and I would like to convert all images now to PNG to display them instead of the SVG file on my website. I would like to use inkscape to conert the images with some good compression.
How can I convert the whole folder into PNG file with a given high where all images have the same name as before? Like test49.svg will be test49.png.
I have tried a few plugins for WordPress with PNG fallback option but they didn’t success.
3 Answers 3
You can process a whole folder of SVG files using Imagemagick, which will offload the work to Inkscape, if it is on your system (at least for versions 6.7.9-0 or higher).
Imagemagick comes with Linux systems and is also available for Mac OSX or Windows.
Using Imagemagick 6:
Change directories to your folder containing the SVG files, then
That command will create the same file names but with .png suffix and place them in the same directory.
If you want to put the PNGs in a different directory, create one (e.g. pngfolder), then
That command will put the resulting PNGs in folder pngfolder.
If on Imagemagick 7, put magick before mogrify.
Set the density for whatever output size you want. Later versions of Inkscape have a default density of 96, so if you want your PNG to be twice as large as the default rendering of the SVG, use 2*96=192, etc.
If you want high quality PNGs at the default density then use -density 384 and add -resize 25% right after that (where 384=4*96 and 25%=1/4)
How to convert a SVG to a PNG with ImageMagick?
I have a SVG file that has a defined size of 16×16. When I use ImageMagick’s convert program to convert it into a PNG, then I get a 16×16 pixel PNG which is way too small:
I need to specify the pixel size of the output PNG. -size parameter seems to be ignored, -scale parameter scales the PNG after it has been converted to PNG. The best result up to now I got by using the -density parameter:
But I’m not satisfied, because I want to specify the output size in pixels without doing math to calculate the density value. So I want to do something like this:
So what is the magic parameter I have to use here?
18 Answers 18
I haven’t been able to get good results from ImageMagick in this instance, but Inkscape does a nice job of it on Linux and Windows:
Edit (May 2020): Inkscape 1.0 users, please note that the command line arguments have changed:
(on macOS, you may need to use —export-file instead of —export-filename ).
Here’s the result of scaling a 16×16 SVG to a 200×200 PNG using this command:
Just for reference, my Inkscape version (on Ubuntu 12.04) is:
and on Windows 7, it is:
svgexport is a simple cross-platform command line tool that I have made for exporting svg files to jpg and png, see here for more options. To install svgexport install npm, then run:
Edit: If you find an issue with the library, please submit it on GitHub, thanks!
20kB. – miek Aug 7 ’15 at 12:19
This is not perfect but it does the job.
Basically it increases the DPI high enough (just use an educated/safe guess) that resizing is done with adequate quality. I was trying to find a proper solution to this but after a while decided this was good enough for my current need.
Note: Use 200×200! to force the given resolution
If you are on MacOS X and having problems with Imagemagick’s convert, you might try reinstalling it with RSVG lib. Using HomeBrew:
Verify that it’s delegating correctly:
It should display rsvg .
Inkscape doesn’t seem to work when svg units are not px (e.g. cm). I got a blank image. Maybe, it could be fixed by twiddling the dpi, but it was too troublesome.
Svgexport is a node.js program and so not generally useful.
Imagemagick’s convert works ok with:
If you use -resize , the image is fuzzy and the file is much larger.
BEST
It is fastest, has the fewest dependencies, and the output is about 30% smaller than convert. Install librsvg2-bin to get it. There does not appear to be a man page but you can type:
to get some assistance. Simple is good.
After following the steps in Jose Alban’s answer, I was able to get ImageMagick to work just fine using the following command:
The number 1536 comes from a ballpark estimate of density, see this answer for more information.
In order to rescale the image, the option -density should be used. As far as I know the standard density is 72 and maps the size 1:1. If you want the output png to be twice as big as the original svg, set the density to 72*2=144:
why don’t you give a try to inkscape command line, this is my bat file to convert all svg in this dir to png:
FOR %%x IN (*.svg) DO C:\Ink\App\Inkscape\inkscape.exe %%x -z —export-dpi=500 —export-area-drawing —export-png=»%%
In ImageMagick, one gets a better SVG rendering if one uses Inkscape or RSVG with ImageMagick than its own internal MSVG/XML rendered. RSVG is a delegate that needs to be installed with ImageMagick. If Inkscape is installed on the system, ImageMagick will use it automatically. I use Inkscape in ImageMagick below.
There is no «magic» parameter that will do what you want.
But, one can compute very simply the exact density needed to render the output.
Here is a small 50×50 button when rendered at the default density of 96:
Suppose we want the output to be 500. The input is 50 at default density of 96 (older versions of Inkscape may be using 92). So you can compute the needed density in proportion to the ratios of the dimensions and the densities.
In ImageMagick 7, you can do the computation in-line as follows:
how to convert .svg image to .png? [duplicate]
I would like to change the color of some SVG pictures and then save them as PNG images. I have installed GIMP. I am running Ubuntu 14.04.
2 Answers 2
With GIMP, open the SVG, then use the Export action from the File menu (or press Ctrl E ):
Select PNG from the drop down menu or the Select File Type list:
Select appropriate settings and export:
You could install Inkscape, open your SVG file in it, do your edits, and use the File > Export PNG image. option ( Shift + Control + e ) to do the conversion.
This is my standard procedure, and it works flawlessly. How well it works for you might depend in the source for your SVG, but certainly worth trying.
It should be possible to do this with Image Magick, as noted in another Q&A, but I always find that a bit trickier to control, and there’s a bit of a learning curve there. It also appears that the «Converseen» front-end hasn’t been updated for Ubuntu 14+, and its website has issues (so far as I can see).
Конвертация svg изображений в PNG или JPEG
Имеется большое количество SVG изображений. Необходимо их конвертировать в PNG или JPEG. Что лучше использовать?
3 ответа 3
Imagemagick, inkscape: оба умеют из командной строки изображения конвертировать
Используйте замечательный пакет Inkscape, который имеет опции импорта/экспорта изображений. На сегодняшний день это самый лучший рендер, который вы сможете найти. Просто запустите inkscape —help и погрузитесь в мир удивительных возможностей, которые дает эта прекрасная программа.
Конечно, есть и другой вариант: вы устанавливаете Chrome и на HTML5, при помощи тега Canvas , отрисовываете все изображения. Ставить софт совершенно не нужно, можно использовать посетителей сайта как распределенный ботнет для вычислений и рендера, что в мире победившего HTML5 является отличной практикой и доступно каждому желающему!