Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/bin/bash -e | |
| 2 # | |
| 3 # This adds text to our non-labeled recovery images. | |
| 4 # | |
| 5 # The source images should be 1366x800, with the expectation they'll be cropped | |
| 6 # to 1366x768 or 1280x800, have 2 lines of text overlayed at the bottom, and | |
| 7 # then be resized to 800x600 so that the BIOS can then display them stretched | |
| 8 # to the full screen size. | |
| 9 # | |
| 10 | |
| 11 # Require one arg | |
| 12 if [ $# -ne "1" ]; then | |
| 13 echo "Usage: $(basename $0) URL" 1>&2 | |
| 14 exit 1 | |
| 15 fi | |
| 16 url=$1 | |
| 17 | |
| 18 | |
| 19 # Image parameters | |
| 20 geom_orig='1366x800' | |
| 21 geom_crop_a='1366x768' | |
| 22 geom_crop_b='1280x800' | |
| 23 geom_final='800x600!' | |
| 24 font="Helvetica-Narrow" | |
| 25 pointsize=30 | |
| 26 | |
| 27 | |
| 28 # Temporary files | |
| 29 tmpdir=$(mktemp -d /tmp/tmp.XXXXXXXXX) | |
| 30 trap "rm -rf $tmpdir" EXIT | |
| 31 img_orig="${tmpdir}/img_orig.bmp" | |
| 32 img_crop_a="${tmpdir}/img_crop_a.bmp" | |
| 33 img_crop_b="${tmpdir}/img_crop_b.bmp" | |
| 34 img_txt_a="${tmpdir}/img_txt_a.bmp" | |
| 35 img_txt_b="${tmpdir}/img_txt_b.bmp" | |
| 36 label_file="${tmpdir}/label.txt" | |
| 37 | |
| 38 # Output directories | |
| 39 outdir_a=$(dirname $0)/out_${geom_crop_a} | |
| 40 [ -d "$outdir_a" ] || mkdir -p "$outdir_a" | |
| 41 outdir_b=$(dirname $0)/out_${geom_crop_b} | |
| 42 [ -d "$outdir_b" ] || mkdir -p "$outdir_b" | |
| 43 | |
| 44 | |
| 45 function find_background_color { | |
| 46 src_img=$1 | |
| 47 convert "$src_img" -crop '1x1+10+10!' txt:- | \ | |
| 48 perl -n -e 'print "$1" if m/(#[0-9a-f]+)/i;' | |
| 49 } | |
| 50 | |
| 51 function process_one_file { | |
| 52 src_img=$1 | |
| 53 | |
| 54 # Figure out the filenames to use | |
| 55 txt_file=${src_img%*.gif}.txt | |
| 56 root=$(basename "$src_img") | |
| 57 root=${root%*.*} | |
| 58 # one more layer of heirarchy to match BIOS source tree | |
| 59 dst_dir_a="${outdir_a}/${root}" | |
| 60 [ -d "$dst_dir_a" ] || mkdir -p "$dst_dir_a" | |
| 61 dst_dir_b="${outdir_b}/${root}" | |
| 62 [ -d "$dst_dir_b" ] || mkdir -p "$dst_dir_b" | |
| 63 dst_img_a="${dst_dir_a}/${root}.bmp" | |
| 64 dst_img_b="${dst_dir_b}/${root}.bmp" | |
| 65 echo "processing $root ..." | |
| 66 | |
| 67 # First, make sure we start with the right-size original | |
| 68 bg=$(find_background_color "$src_img") | |
| 69 convert "$src_img" -background "$bg" \ | |
| 70 -gravity center -extent $geom_orig "$img_orig" | |
| 71 | |
| 72 # Now crop that to the two target sizes | |
| 73 convert "$img_orig" -gravity Center \ | |
| 74 -crop "$geom_crop_a"+0+0 +repage "$img_crop_a" | |
| 75 convert "$img_orig" -gravity Center \ | |
| 76 -crop "$geom_crop_b"+0+0 +repage "$img_crop_b" | |
| 77 | |
| 78 # Add the labels in | |
| 79 if [ -r "$txt_file" ]; then | |
| 80 # Replace all '$URL' in the URL in the text file with the real url | |
| 81 perl -p \ | |
| 82 -e 'BEGIN {$/ = ""; $url = shift; }' \ | |
| 83 -e 'chomp; s/\$URL/$url/gse;' \ | |
| 84 -e 'END {print "\n";}' "$url" "$txt_file" > "$label_file" | |
| 85 # Render it | |
| 86 convert "$img_crop_a" -fill white \ | |
| 87 -font "$font" -pointsize "$pointsize" -interline-spacing 5 \ | |
| 88 -gravity south -annotate '+0+10' '@'"$label_file" "$img_txt_a" | |
| 89 convert "$img_crop_b" -fill white \ | |
| 90 -font "$font" -pointsize "$pointsize" -interline-spacing 5 \ | |
| 91 -gravity south -annotate '+0+10' '@'"$label_file" "$img_txt_b" | |
| 92 else | |
| 93 mv "$img_crop_a" "$img_txt_a" | |
| 94 mv "$img_crop_b" "$img_txt_b" | |
| 95 fi | |
| 96 | |
| 97 # Now scale the result to the final size | |
| 98 convert "$img_txt_a" -scale "$geom_final" -alpha off "$dst_img_a" | |
| 99 convert "$img_txt_b" -scale "$geom_final" -alpha off "$dst_img_b" | |
| 100 } | |
| 101 | |
| 102 | |
| 103 # Do it. | |
|
Randall Spangler
2010/08/16 15:45:56
(process all files)
| |
| 104 for file in originals/*.gif; do | |
| 105 process_one_file "$file" | |
| 106 done | |
| OLD | NEW |