Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active August 13, 2024 17:12
Show Gist options
  • Save WebReflection/b5ab5f1eca311b76835c to your computer and use it in GitHub Desktop.
Save WebReflection/b5ab5f1eca311b76835c to your computer and use it in GitHub Desktop.
Transform AI to SVG, requires Inkscape

Save this file as ai2svg, make it executable via chmod +x ai2svg then run it optionally passing the folder to look for.

It will convert in that folder, or the current one, all .ai files into .svg

#!/usr/bin/bash

createsvg() {
  local margin="$1"
  local d
  local svg
  for d in *.ai; do
    svg=$(echo "$d" | sed 's/.ai/.svg/')
    echo "creating $svg ..."
    # old version: inkscape "$d" -l -o "$svg"
    if [ "$margin" != "" ]; then
      inkscape "$d" --export-area-drawing --export-margin $margin "--export-plain-svg=$svg"
    else
      inkscape "$d" --export-area-drawing "--export-plain-svg=$svg"
    fi
  done
}

if [ "$1" != "" ];then
  cd $1
fi

createsvg "$2"
@asbjornu
Copy link

I had to add d=$(echo "$(cd "$(dirname "$d")"; pwd)/$(basename "$d")") as the first line of the for loop to make the path to $d absolute, otherwise inkscape just erred that it couldn't find the file.

@mrohnstock
Copy link

since inkscape > v1.0 the parameter did changed:

inkscape "$d" -l -o "$svg"

@WebReflection
Copy link
Author

@mrohnstock updated, thanks

@bcag2
Copy link

bcag2 commented Jan 11, 2022

with the v0.92.3 (default version with ubuntu 18.04), -o are not defined, so I remove it (and add --export-area-drawing) :

inkscape myDrawing.ai --export-area-drawing -l myDrawing.svg
# or with full text option :
inkscape myDrawing.ai --export-area-drawing --export-plain-svg=myDrawing.svg

I would like to add margins around drawing but it seems not possible

@WebReflection
Copy link
Author

@bcag2 thanks

@MaydayGD
Copy link

Can you please add instructions for the AI to SVG for people that have no idea what to do with the above and how to get it to work?

I have a folder full of AI that I need to convert to SVG. Google gave me this as a top search result, but I do not see an explanation or instructions how to get this to work on PC. Thank you.

@WebReflection
Copy link
Author

WebReflection commented Jan 18, 2022

./ai2svg ./folder/path

You need a command line on Linux, it might work on macOS too, if you have Inkscape, but if you’re windows’ user please look at any further result in Google or try with WSL

@MaydayGD
Copy link

Thank you for replying that doesn't work on Windows. I will see other options.

@WebReflection
Copy link
Author

@MaydayGD no problem, but in general, when you see #!/usr/bin/bash (shebang) on top of any script/file, that's usually for linux/macos shell, not windows 👋

@bcag2
Copy link

bcag2 commented Jan 20, 2022

Contrary to what I wrote in my previous post, It is possible to add margins, look at SO ticket :
https://graphicdesign.stackexchange.com/a/155523/144183
--export-margin 20 where 20 is in pixels "user unit"

@WebReflection
Copy link
Author

@bcag2 so ... optional extra arg?

@bcag2
Copy link

bcag2 commented Feb 18, 2022

Yes!

@Its-Just-Nans
Copy link

A useful options to know is also --export-text-to-path :)

@adrianoresende
Copy link

Warning: Option --export-plain-svg= is deprecated

@bcag2
Copy link

bcag2 commented Aug 12, 2024

Warning: Option --export-plain-svg= is deprecated

any source, inkscape version, replacement solution ?

@adrianoresende
Copy link

Warning: Option --export-plain-svg= is deprecated

any source, inkscape version, replacement solution ?

Inkscape 1.3.2 (091e20e, 2023-11-25)

My SVG was converted without color; then I set the colors manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment