If you want to convert SVG files repeatedly, it is bothering to open and save files each time. Then CairoSVG is a good python library for converting SVG to PNG. But building a python environment is also bothering me, so this repository manages the following things.
- Dockerfile for environment to use python and CairoSVG
- python code for batch file conversion
- Memorandum for docker commands
- Install docker.
- Build Dockerfile with following command.
docker build -t python-cairosvg:latest .
- Run docker image with mounting current directory as working directory.
docker run --rm -it -v $(pwd):/var/python python-dl bash
-
Put SVG file (ex. image.svg) to src directory.
-
Run cairosvg command.
cairosvg src/image.svg -o dst/image.png
- Run docker image with mounting current directory as working directory.
docker run --rm -it -v $(pwd):/var/python python-cairosvg bash
-
Put SVG files (ex. image.svg) to src directory.
-
Run python script.
python convert.py
- All SVG files inside ./src will be converted and saved to ./dst
If you build Dockerfile after updating it, the previous build may remain like following log.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
python-dl latest c6d6f509ae5b 3 seconds ago 1.21GB
<none> <none> 6e119ff05b9e About a minute ago 1.21GB <- Previous build
python latest a4cc999cf2aa 2 days ago 929MB
Then you can cleanup these images by following command.
docker rmi $(docker images -qa -f 'dangling=true')