forked from zoezhu/png2svg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_svg.py
121 lines (75 loc) · 2.66 KB
/
get_svg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# PNG2SVG
[![CC BY-NC-SA 4.0][cc-by-nc-sa-shield]][cc-by-nc-sa]
Convert images from png/jpg format to svg.
## Install
Clone repo.
```shell
# Use whole functions with sr, highly recommand
git clone --recursive https://github.com/zoezhu/png2svg.git
# OR
# Do not use sr, no need to install torch and Real-ESRGAN, with performance degradation
git clone https://github.com/zoezhu/png2svg.git
```
- Regular library
```shell
pip install -r requirements.txt
```
- Potrace
Ubuntu:
```shell
# install system dependencies
sudo apt-get install build-essential python-dev libagg-dev libpotrace-dev pkg-config
# Install pypotrace
cd pypotrace
pip install numpy
pip install .
cd ..
```
CentOS/OSX/Windows install steps can be found in [Potrace](https://pypi.org/project/pypotrace/) site.
- Real-ESRGAN (highly recommend)
```shell
cd Real-ESRGAN
pip install basicsr
# facexlib and gfpgan are for face enhancement
pip install facexlib
pip install gfpgan
pip install -r requirements.txt
python setup.py develop
```
Install [torch](https://pytorch.org/) with corresponding version of your machine.
```shell
# default install, please check your machine and choose right version
pip3 install torch
```
Download model file.
```shell
# Make sure under Real-ESRGAN folder
# RealESRGAN_x4plus_anime_6B.pth, good for anime style input
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth -P weights
# RealESRGAN_x4plus.pth
wget https://github.com/xinntao/Real-ESRGAN/releases/download/v0.1.0/RealESRGAN_x4plus.pth -P weights
```
## Usage
Input path can be a file or a folder.
```text
Usage: python get_svg.py
-f file required=True, type=str, Input image folder or single image path.
-c color type=int, default=-1, How many colors you want to draw.
-sr do_sr Wheather do super resolution for input image.
```
Run the script.
```shell
# Use sr to make better performance
python get_svg.py -f test_img/test.png -sr
# OR
# Do not use sr
python get_svg.py -f test_img/test.png
```
Output svg file is under the same path as input file, with the same name but suffix is “svg”.
## License
This work is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License][cc-by-nc-sa].
[![CC BY-NC-SA 4.0][cc-by-nc-sa-image]][cc-by-nc-sa]
[cc-by-nc-sa]: http://creativecommons.org/licenses/by-nc-sa/4.0/
[cc-by-nc-sa-image]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
[cc-by-nc-sa-shield]: https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-lightgrey.svg
PNG2SVG © 2023 by zoezhu is licensed under CC BY-NC-SA 4.0