From https://gist.github.com/ykarikos/2892009
- bash script
- bad results for thin text in small image
- only output to color black
- Require potrace libpotrace0
Beware for copyright terms for font used,
Font preivew: https://m.fontke.com/font/10131021/preview/
tested img: https://i.imgur.com/KYvv3jW.jpg
file sizes: zh-list3.txt
Simply ./png2svg.sh input_png
output input_svg.
Not recommand to convert $a -fuzz 10% -transparent white $o
7.3k png -> 6.1k svg, as transparent image would become inverted cutout.
Optimize svg file size with, https://jakearchibald.github.io/svgomg/
3.5k png -> 8.0k svg -> 4.0k svg
extract text from white subtitle in video, convert input_img -colorspace Gray -negate -gamma 40 out_png
text dump
# textcleaner: http://www.fmwconcepts.com/imagemagick/textcleaner/
# pngcrush -reduce png file size -not tested
# filter out tested
mapfile -t rs < <(ls *svg|cut -d. -f1)
mapfile -t tv < <(ls|grep -v ${rs[@]/#/-e }|grep -v png)
for i in "${tv[@]}";do o='${i%.*}.png'; convert $i $o;../png2svg.sh $o;done
#o=$(echo ${i%.*}.png|tr ' ' '_') # replace space with underscore
ls >filelist.txt; sed -i '/^filelist/d'
# crop out borders, remove 30px right side
convert $a -gravity Center -crop 83%\! -gravity East -chop 30x0 $o
# x1 y2, x2 y2 > x y : 105 361, 1907 1021 > 1802 660
convert $a -gravity center -crop 1802x660+0+0\! +repage $o
# huge gap in image > use gimp. Use fred script to cleanup image.
./shadowhighlight -sa 60 -ha 60 -ma 70 $o hclean.png
e="-g -e normalize -s 5 -T -u -t 2 -f 15 -o 6"
./textcleaner $e hclean.png hclean2.png
du -ach . #list file size and total, human readable
cat filelist.txt| cut -d. -f1|uniq|while read i;do du -ach "$i"*;done > listSize.txt;
# read file, find line exclude 'svg'. Get width and height
cat filelist.txt| grep -v svg| while read i;do identify -ping -format '%wx%h' "$i";echo '';done > listWH.txt;
# check line number, need to be same
cat listSize.txt |grep -nEv 'total|svg'|wc -l; #27
cat listWH.txt|wc -l #27
# read file, find line and line number exclude 'total' or 'svg'.
mapfile -t rs < <(cat listSize.txt |grep -nEv 'total|svg'|cut -d: -f1);
cp listSize.txt listsz2.txt
# join a file line by line to another file by line numbers
line=0;for i in "${rs[@]}";do line=$((line+1)); WH=$(cat listWH.txt|awk "NR==$line");sed -i $i"s/$/ $WH/" listsz2.txt;done
#echo $i $WH;done #debug
#sed -i '/.svg/ s/$/ -/' listsz2;sed -i "/total/{G;}" listsz2
# add dash to line contain 'svg'
sed -i '/.svg/ s/$/ -/' listsz2.txt
# rearrange output to column, add newline after line contain 'total'
cat listsz2.txt |awk '{print $1,$3,$2}'|column -t|sed '/total/{G;}' > list2.txt;
# manually convert svg to png using gimp ... x-images
# move some files to folder
mv `ls vert|cut -d. -f1|uniq|sed 's/$/*/'` vert/
convert x1.png x2.png x3.png \
\( x4.png x5.png -gravity center -extent 1024x \) \
-append -resize 70% zh-list.jpg
svg to png ref:
online converter https://runemadsen.com/svg-converter/
need inkscape https://stackoverflow.com/questions/9853325/how-to-convert-a-svg-to-a-png-with-image-magick
need librsvg2-bin https://ubuntuforums.org/showthread.php?t=820965
Chinese name gen. richyli.com/name/index.asp