Closed wendashi closed 6 months ago
I found some info from svgrender/PyTorch-SVGRender/data/alphabet1.svg
. But I'm not sure if every svg file from "Adobe Illustrator 25.0.1, SVG Export Plug-In" can be the inputs of CLIPFont?
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 25.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
May I use some python script or library to process the .ttf into svg which is suitable for CLIPFont? 🤔
Dear wendashi,
I'm not sure, but it's possible that the output from Adobe Illustrator contains tags that are not supported in DiffVG. Yes, I suggest using FreeType to process .ttf files into SVG.
Additionally, you can try the Word-As-Img pipeline in PyTorch-SVGRender, which will allow you to obtain glyphs in vector format.
Dear ximing,
Thanks for your advice❤️.And I found a pixels2svg (https://pypi.org/project/pixels2svg/) can process a 512 x 512 png into the svg format which is suitable for CLIPFont.
But I guess it's still need extra process for more colorful results like the pics in the CLIPFont paper. In the paper, it mentioned the enhancement of original svg as following:
"Specifically, for each vector polygon, increase the number of control points on the boundary. In addition, vector polygon layers are stacked in the channel dimension to expand the parameter search space. Last but not the least, we apply a random color gradient to the input monochromatic font and divide it into multiple small polygons by color similarity. "
Do you have any advice for it? Thanks a lot🙏 And If I can reproduce it, I also can contribute the code to svgrender.
Additionally, I have tried the Word-As-Img pipeline, but I think it's only suitable for English letters? Cause it defines a rule of control points for each English letters in '/path/to/svgrender/PyTorch-SVGRender/pytorch_svgrender/painter/wordasimage/painter_params.py'
. 🤔
def preprocess_font(self, word, letter, level_of_cc=1, font_path=None, init_path=None):
if level_of_cc == 0:
target_cp = None
else:
target_cp = {"A": 120, "B": 120, "C": 100, "D": 100,
"E": 120, "F": 120, "G": 120, "H": 120,
"I": 35, "J": 80, "K": 100, "L": 80,
"M": 100, "N": 100, "O": 100, "P": 120,
"Q": 120, "R": 130, "S": 110, "T": 90,
"U": 100, "V": 100, "W": 100, "X": 130,
"Y": 120, "Z": 120,
"a": 120, "b": 120, "c": 100, "d": 100,
"e": 120, "f": 120, "g": 120, "h": 120,
"i": 35, "j": 80, "k": 100, "l": 80,
"m": 100, "n": 100, "o": 100, "p": 120,
"q": 120, "r": 130, "s": 110, "t": 90,
"u": 100, "v": 100, "w": 100, "x": 130,
"y": 120, "z": 120}
target_cp = {k: v * level_of_cc for k, v in target_cp.items()}
Dear wendashi,
Note that the SVG path obtained through pixel2svg does not contain the fill_color
parameter, because this is the color parameter optimized by clipfont.
In addition, it is basically the same with word-as-img about the boundary control of detailed graphics (The part of the code you show).
word-as-img currently manually defines the number of control points for English letters only. I think for Chinese, the situation is more complicated.
best regards, ximing
Dear ximing,
Thanks for your advice, I think I make it. Just convert the black words SVG into PNG, and write a python script to fill the PNG color with gird, and then convert the colorful PNG back to SVG.
Thanks for your awesome job❤️ I reproduced the CLIPFont.
But when I use new input svg file, I meet some Error. I thought maybe I need to process the svg into a certain format? Could you please give me some advice? Thanks a lot🙏
python svg_render.py x=clipfont prompt='Starry Night by Vincent van gogh' target='./data/test1.svg'