3 ms·
Use wkhtmltoimage to create images of book-quality syntax-highlighted source code: http://superuser.com/questions/213217/convert-html-to-image http://superuser
by thangalin 16y ago
Use wkhtmltoimage to create images of book-quality syntax-highlighted source code:
http://superuser.com/questions/213217/convert-html-to-image http://superuser.com/questions/213217/convert-html-to-image
Use gvim to pick from 100 different ready-made colour schemes:
http://www.vi-improved.org/color_sampler_pack/ http://www.vi-improved.org/color_sampler_pack/
Shameless plug: I describe this technique in an appendix of my technical manual.
http://www.whitemagicsoftware.com/books/indispensable/ http://www.whitemagicsoftware.com/books/indispensable/
For example:
#!/bin/bash
echo Converting $1 to $1.html...
# Schemes: pyte
vim $1 -c "set nobackup" ${2:+"-c set number"} \
-c ":colorscheme tango-morning" \
-c ":TOhtml" \
-c "wq" -c ":q"
echo Converting $1.html to $1.png...
wkhtmltoimage --transparent --minimum-font-size 80 \
--format png --quality 100 --width 4000 \
$1.html $1.png
mv $1.png $1.orig.png
# For scripts that are under 80 characters, make the generated image always
# the same size (4000 pixels = width + (border x 2) = 3950 + 25 x 2).
LENGTH=$(awk 'BEGIN {x=0} {if( length($0)>x ) x=length()} END {print x;}' $1)
if [ $LENGTH -le 80 ]; then
EXTENT=true
fi
echo Trimming $1.png...
convert -format png $1.orig.png -background none -antialias -trim +repage \
-density 150x150 ${EXTENT:+-extent 3950x} \
-bordercolor none -border 25 \
$1.png
echo Removing temporary files...
rm -f $1.orig.png
rm -f $1.html