OLD | NEW |
1 #!/bin/bash -e | 1 #!/bin/bash -e |
2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 # | 5 # |
6 # This adds text to our non-labeled recovery images. | 6 # This adds text to our non-labeled recovery images. |
7 # | 7 # |
8 # The source images should be 1366x800, with the expectation they'll be cropped | 8 # The source images should be 1366x800, with the expectation they'll be cropped |
9 # to 1366x768 or 1280x800, have 2 lines of text overlayed at the bottom, and | 9 # to 1366x768 or 1280x800, have 2 lines of text overlayed at the bottom, and |
10 # then be resized to 800x600 so that the BIOS can then display them stretched | 10 # then be resized to 800x600 so that the BIOS can then display them stretched |
11 # to the full screen size. | 11 # to the full screen size. |
12 # | 12 # |
13 | 13 |
| 14 |
| 15 |
| 16 |
14 # Require one arg | 17 # Require one arg |
15 if [ $# -ne "1" ]; then | 18 if [ $# -ne "1" ]; then |
16 echo "Usage: $(basename $0) URL" 1>&2 | 19 echo "Usage: $(basename $0) MODEL" 1>&2 |
17 exit 1 | 20 exit 1 |
18 fi | 21 fi |
19 url=$1 | 22 MODEL=$1 |
| 23 |
| 24 # Default URL |
| 25 URL='http://google.com/chromeos/recovery' |
20 | 26 |
21 | 27 |
22 # Image parameters | 28 # Image parameters |
23 geom_orig='1366x800' | 29 geom_orig='1366x800' |
24 geom_crop_a='1366x768' | 30 geom_crop_a='1366x768' |
25 geom_crop_b='1280x800' | 31 geom_crop_b='1280x800' |
26 geom_final='800x600!' | 32 geom_final='800x600!' |
27 font="Helvetica-Narrow" | 33 bluecolor='#9ccaec' |
28 pointsize=30 | 34 bluefont="Helvetica-Narrow" |
| 35 bluepointsize=30 |
| 36 whitefont="Helvetica-Narrow" |
| 37 whitepointsize=48 |
29 | 38 |
30 | 39 |
31 # Temporary files | 40 # Temporary files |
32 tmpdir=$(mktemp -d /tmp/tmp.XXXXXXXXX) | 41 tmpdir=$(mktemp -d /tmp/tmp.XXXXXXXXX) |
33 trap "rm -rf $tmpdir" EXIT | 42 trap "rm -rf $tmpdir" EXIT |
34 img_orig="${tmpdir}/img_orig.bmp" | 43 img_orig="${tmpdir}/img_orig.bmp" |
35 img_crop_a="${tmpdir}/img_crop_a.bmp" | 44 img_crop_a="${tmpdir}/img_crop_a.bmp" |
36 img_crop_b="${tmpdir}/img_crop_b.bmp" | 45 img_crop_b="${tmpdir}/img_crop_b.bmp" |
37 img_txt_a="${tmpdir}/img_txt_a.bmp" | 46 img_txt_a="${tmpdir}/img_txt_a.bmp" |
38 img_txt_b="${tmpdir}/img_txt_b.bmp" | 47 img_txt_b="${tmpdir}/img_txt_b.bmp" |
39 label_file="${tmpdir}/label.txt" | 48 label_file="${tmpdir}/label.txt" |
| 49 label_img="${tmpdir}/label.bmp" |
40 | 50 |
41 # Output directories | 51 # Output directories |
42 thisdir=$(readlink -e $(dirname $0)) | 52 thisdir=$(readlink -e $(dirname $0)) |
43 outdir_a=${thisdir}/out_${geom_crop_a} | 53 outdir_a=${thisdir}/out_${geom_crop_a} |
44 [ -d "$outdir_a" ] || mkdir -p "$outdir_a" | 54 [ -d "$outdir_a" ] || mkdir -p "$outdir_a" |
45 outdir_b=${thisdir}/out_${geom_crop_b} | 55 outdir_b=${thisdir}/out_${geom_crop_b} |
46 [ -d "$outdir_b" ] || mkdir -p "$outdir_b" | 56 [ -d "$outdir_b" ] || mkdir -p "$outdir_b" |
47 | 57 |
48 | 58 |
49 function find_background_color { | 59 function find_background_color { |
(...skipping 24 matching lines...) Expand all Loading... |
74 -gravity center -extent $geom_orig "$img_orig" | 84 -gravity center -extent $geom_orig "$img_orig" |
75 | 85 |
76 # Now crop that to the two target sizes | 86 # Now crop that to the two target sizes |
77 convert "$img_orig" -gravity Center \ | 87 convert "$img_orig" -gravity Center \ |
78 -crop "$geom_crop_a"+0+0 +repage "$img_crop_a" | 88 -crop "$geom_crop_a"+0+0 +repage "$img_crop_a" |
79 convert "$img_orig" -gravity Center \ | 89 convert "$img_orig" -gravity Center \ |
80 -crop "$geom_crop_b"+0+0 +repage "$img_crop_b" | 90 -crop "$geom_crop_b"+0+0 +repage "$img_crop_b" |
81 | 91 |
82 # Add the labels in | 92 # Add the labels in |
83 if [ -r "$txt_file" ]; then | 93 if [ -r "$txt_file" ]; then |
84 # Replace all '$URL' in the URL in the text file with the real url | 94 # The only way to change font and color in multiline text is to split each |
85 perl -p \ | 95 # line into a separate image and then composite them together. Ugh. |
86 -e 'BEGIN {$/ = undef; $url = shift; }' \ | 96 # First, split each input line into a separate file. |
87 -e 's/\s+$/\n/gs; s/\$URL/$url/gs;' \ | 97 "${thisdir}/makelines" -u "$URL" -m "$MODEL" -d "$tmpdir" "$txt_file" |
88 "$url" "$txt_file" > "$label_file" | 98 # Convert each line file into an image file. |
89 # Render it | 99 for txtfile in ${tmpdir}/linetxt_*; do |
90 convert "$img_crop_a" -fill white \ | 100 case "$txtfile" in |
91 -font "$font" -pointsize "$pointsize" -interline-spacing 5 \ | 101 *.txt) |
92 -gravity south -annotate '+0+0' '@'"$label_file" "$img_txt_a" | 102 convert \ |
93 convert "$img_crop_b" -fill white \ | 103 -background "$bg" -fill "$bluecolor" \ |
94 -font "$font" -pointsize "$pointsize" -interline-spacing 5 \ | 104 -font "$bluefont" -pointsize "$bluepointsize" \ |
95 -gravity south -annotate '+0+0' '@'"$label_file" "$img_txt_b" | 105 -bordercolor "$bg" -border 0x1 \ |
| 106 label:'@'"$txtfile" "${txtfile%.*}".bmp |
| 107 ;; |
| 108 *.TXT) |
| 109 convert \ |
| 110 -background "$bg" -fill "white" \ |
| 111 -font "$whitefont" -pointsize "$whitepointsize" \ |
| 112 -bordercolor "$bg" -border 0x10 \ |
| 113 label:'@'"$txtfile" "${txtfile%.*}".bmp |
| 114 ;; |
| 115 esac |
| 116 done |
| 117 # Now bash them all together to make one image. |
| 118 convert -background "$bg" -gravity center ${tmpdir}/linetxt_*.bmp \ |
| 119 label:'\n\n\n\n' -append "$label_img" |
| 120 # Finally, layer the label image on top of the original. |
| 121 composite "$label_img" -gravity south "$img_crop_a" "$img_txt_a" |
| 122 composite "$label_img" -gravity south "$img_crop_b" "$img_txt_b" |
96 else | 123 else |
97 mv "$img_crop_a" "$img_txt_a" | 124 mv "$img_crop_a" "$img_txt_a" |
98 mv "$img_crop_b" "$img_txt_b" | 125 mv "$img_crop_b" "$img_txt_b" |
99 fi | 126 fi |
100 | 127 |
101 # Now scale the result to the final size | 128 # Now scale the result to the final size |
102 convert "$img_txt_a" -scale "$geom_final" -alpha off "$dst_img_a" | 129 convert "$img_txt_a" -scale "$geom_final" -alpha off "$dst_img_a" |
103 convert "$img_txt_b" -scale "$geom_final" -alpha off "$dst_img_b" | 130 convert "$img_txt_b" -scale "$geom_final" -alpha off "$dst_img_b" |
104 } | 131 } |
105 | 132 |
106 | 133 |
107 # Do it. | 134 # Do it. |
108 for file in originals/*.gif; do | 135 for file in originals/*.gif; do |
109 process_one_file "$file" | 136 process_one_file "$file" |
110 done | 137 done |
111 | 138 |
112 # Zip up the bitmaps | 139 # Zip up the bitmaps |
113 nicename=${url// /_} | 140 nicename=${MODEL// /_} |
114 (cd "$outdir_a" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_a}.zip" *) | 141 (cd "$outdir_a" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_a}.zip" *) |
115 (cd "$outdir_b" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_b}.zip" *) | 142 (cd "$outdir_b" && zip -qr "${thisdir}/out_${nicename}__${geom_crop_b}.zip" *) |
OLD | NEW |