OLD | NEW |
(Empty) | |
| 1 #!/bin/bash -e |
| 2 # Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 # |
| 6 # Render a text file into a bitmap. |
| 7 # |
| 8 |
| 9 # Image parameters |
| 10 bg='#607c91' |
| 11 bluecolor='#9ccaec' |
| 12 bluefont="Helvetica-Narrow" |
| 13 bluepointsize=19 |
| 14 whitefont="Helvetica-Narrow" |
| 15 whitepointsize=30 |
| 16 |
| 17 |
| 18 tmpdir=$(mktemp -d /tmp/tmp.bmp.XXXXXX) |
| 19 trap "rm -rf $tmpdir" EXIT |
| 20 label_file="${tmpdir}/label.txt" |
| 21 |
| 22 for txtfile in $*; do |
| 23 bmpfile="${txtfile%.*}".bmp |
| 24 perl -p -e 'BEGIN{ $/=undef; }' \ |
| 25 -e 's/^\s+//s;' -e 's/\s+$//s;' \ |
| 26 "$txtfile" > "$label_file" |
| 27 |
| 28 case "$txtfile" in |
| 29 *.txt) |
| 30 convert \ |
| 31 -background "$bg" -fill "$bluecolor" \ |
| 32 -font "$bluefont" -pointsize "$bluepointsize" \ |
| 33 -bordercolor "$bg" -border 0x1 -gravity Center \ |
| 34 label:'@'"$label_file" \ |
| 35 -colors 256 -compress none -alpha off \ |
| 36 "$bmpfile" |
| 37 echo "wrote $bmpfile" |
| 38 ;; |
| 39 *.TXT) |
| 40 convert \ |
| 41 -background "$bg" -fill "white" \ |
| 42 -font "$whitefont" -pointsize "$whitepointsize" \ |
| 43 -bordercolor "$bg" -border 0x10 -gravity Center \ |
| 44 label:'@'"$label_file" \ |
| 45 -colors 256 -compress none -alpha off \ |
| 46 "$bmpfile" |
| 47 echo "wrote $bmpfile" |
| 48 ;; |
| 49 *) |
| 50 echo "Ignoring $txtfile. Filname should end with .txt or .TXT" |
| 51 ;; |
| 52 esac |
| 53 done |
OLD | NEW |