Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


High DPI png from code

28 Oct 2023 »

https://stackoverflow.com/questions/3938953/convert-source-code-to-syntax-highlighted-image

setup

yum -y install libglvnd
gvim
yum -y install libglvnd-devel
wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox-0.12.6-1.centos7.x86_64.rpm
yum -y install wkhtmltox-0.12.6-1.centos7.x86_64.rp
yum -y install compat-openssl10
yum -y install ghostscript
yum search imagemagick
#!/bin/bash -x
file=$1
[ -f ${file}.html ] && rm -f ${file}.html
[ -f ${file}.ps ] && rm -f ${file}.ps
[ -f ${file}.raw.png ] && rm -f ${file}.raw.png
[ -f ${file}.png ] && rm -f ${file}.png

gvim -e $file -c "set nobackup" -c ":colorscheme moria" -c :TOhtml -c wq -c :q
#gvim -e $file -c "set nobackup" -c ":colorscheme zellner" -c :TOhtml -c wq -c :q
until ls ${file}.html; do sleep 1; done
wkhtmltopdf --quiet --dpi 1200 ${file}.html ${file}.ps

gs -q -dBATCH -dNOPAUSE -dSAFER -dNOPROMPT \
 -sDEVICE=png16m -dDEVICEXRESOLUTION=600 -dDEVICEYRESOLUTION=600 \
 -dDEVICEWIDTH=4958 -dDEVICEHEIGHT=7017 -dNOPLATFONTS \
 -dTextAlphaBits=4 -sOutputFile=${file}.raw.png ${file}.ps
 
 
convert -trim +repage -trim +repage \
  -bordercolor "#f0f0f0" -border 25x25 ${file}.raw.png ${file}