Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch command for ImageMagick to convert all files in a directory and sub-directories on windows

I have thousands of SVG's in a folder and sub-folders. What I want is to batch convert all of them to jpg or png images.

Can someone help me write a command for ImageMagick (windows), which can find and convert all the svg's to jpg/png with their original names and keep them in the same directories?

Here is the example structure:

C:\SVG\BusinessMan.svg
C:\SVG\Models\Home.svg
C:\SVG\Underlines\underline.svg

And I want it like this after conversion:

C:\SVG\BusinessMan.svg
C:\SVG\BusinessMan.jpg
C:\SVG\Models\Home.svg
C:\SVG\Models\Home.jpg
C:\SVG\Underlines\underline.svg
C:\SVG\Underlines\underline.jpg
like image 893
Key Avatar asked May 23 '15 15:05

Key


2 Answers

you don't need shell scripting just use the mogrify command

cd to your image directory

mogrify -format png *.svg
like image 187
temi007 Avatar answered Sep 17 '22 13:09

temi007


Try with a FOR loop with /R flag from inside your root folder:

FOR /R %a IN (*.svg) DO convert "%~a" "%~dpna.jpg"

this command will convert all the .svg files in your sub-directories under the root folder you launched your command from.

Above command works for command line, if you plan to use the command inside a batch file (.bat) remember to use %% instead of %:

FOR /R %%a IN (*.svg) DO convert "%%~a" "%%~dpna.jpg"

See this page of Imagemagick documentation for more info

like image 41
Andrea Avatar answered Sep 19 '22 13:09

Andrea