Convert folder of .svg to 256x256 .ico

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
firewater
Posts: 2
Joined: 2014-04-11T20:25:35-07:00
Authentication code: 6789

Convert folder of .svg to 256x256 .ico

Post by firewater »

The title pretty much sums it up. I'm running ImageMagick and I'm really bad at this, it took me a while to understand that I had to open convert.exe from CMD so it wouldn't close itself.

I have a bunch of .svg files located at C:\Users\Cristian\Documents\Downloads\flattr-icons-master\flattr-icons-master\actions\scalable that I would like to convert to 256x256 .ico

I tried

Code: Select all

CD C:\Users\Cristian\Documents\Downloads\flattr-icons-master\flattr-icons-master\actions\scalable
and then

Code: Select all

convert file1.svg file1.ico
but I get a 48x48 file instead of the 256x256 one I want. It also has a white background instead of a transparent one.

Plus I was wondering if there was a way to make the whole process faster... like, instead of having to write

Code: Select all

convert file1.svg file2.ico
for each file maybe there is a line of code that can automatize the whole process and convert all files in the folder to .ico with given parameters (no quality loss, 256x256 size, etc)?

So yeah what would be the exact line of code I should use for this purpose?

Thank you for reading.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert folder of .svg to 256x256 .ico

Post by fmw42 »

I am not an expert on ICO files, since I do not use Windows, nor am I an SVG expert. But SVG files are vector files and I believe the size depends upon the density assigned to it. I could be wrong about this. If you want a 256x256 ICO, you need to have a 256x256 size input image. So you must assign a density to achieve this size.

If the size is built in, then you must modify your SVG files to make 256x256 images when displayed or read or resize them using -resize.

density=256*72/48=384

So this might do it.

Code: Select all

convert -density 384 file1.svg file1.ico
If you want multiple sizes in the ICO. Then you need to use the ICO define

Code: Select all

convert -density 384 file1.svg -define icon:auto-resize file1.ico
see
http://www.imagemagick.org/script/comma ... php#define

However, mogrify should be able to do all your images in any one folder at one time.

see
http://www.imagemagick.org/Usage/basics/#mogrify

# create a new directory, so you do not overwrite your old one. Say folder2. Assume you images are in folder1. Cd or whatever the Windows equivalent is to folder1 holding your images.

Code: Select all

mogrify -path path2/folder2 -format ico -density 384 *.svg
This assumes that all your svg files need the same density to achieve 256x256 pixel size. A way around this would be to use a large density and then resize to 256x256

Code: Select all

convert -density 600 file1.svg -resize 256x256 file1.ico
or

Code: Select all

mogrify -path path2/folder2 -format ico -density 600 -resize 256x256 *.svg
Of course this assumes your input svg files are created so that they are square. If not, then you have to decide whether you want to pad to square or crop to square. If cropping, then 256x256^^ or "256x256^" in windows syntax. Note there are difference between windows syntax and unix syntax. See http://www.imagemagick.org/Usage/windows/


I have not tested this, since I am not on windows.

Perhaps some Windows user can test and correct me if I am wrong about this.

If you are not on a current version of Imagemagick, the -define may not work. You do not say. It is usually a good idea to identify your version of Imagemagick and platform.

You can get the IM version using

Code: Select all

convert -version

For new users, see
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert folder of .svg to 256x256 .ico

Post by snibgo »

You can resize to make the image exactly 256x256:

Code: Select all

convert in.svg -resize "256x256^!" out.ico
For doing all the svg files in a directory, you could use wildcards or the "mogrify" command. But I generally use the Windows "for" command, eg

Code: Select all

for /F "usebackq" %%F ^
in (`dir /B *.svg`) ^
do convert %%F -resize "256x256^!" %%~nF.ico
(Windows BAT syntax, so each % is doubled.)
snibgo's IM pages: im.snibgo.com
firewater
Posts: 2
Joined: 2014-04-11T20:25:35-07:00
Authentication code: 6789

Re: Convert folder of .svg to 256x256 .ico

Post by firewater »

Thank you for answering, but I'm having a problem with both methods.

Image

I googled and it sems like I have to install some libraries for a particular type of .svg or something like that, but I installed Inkscape and It's still the same so I don't know how to proceed.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert folder of .svg to 256x256 .ico

Post by snibgo »

What happens when you type:

Code: Select all

inkscape folder_images.svg
Inkscape should fire up interactively, which takes a few seconds, then display the image represented by your SVG file.

If Inkscape doesn't fire up, then it hasn't installed properly or isn't in your path.

If it fires up but reports a problem with the SVG file, then that's the problem.

If Inkscape shows your image, then there is something wrong with the IM installation, or it can't read the first part of the SVG for some reason.
snibgo's IM pages: im.snibgo.com
Post Reply