site

personal website, served at mordaunt.dev/site
Log | Files | Refs

resize-images (1239B)


      1 #!/bin/sh
      2 # resize-images - regenerate the derived images from their originals.
      3 #
      4 # The avatar is displayed in a 20rem (320 px) slot and the favicons at 32
      5 # and 16 px; the originals are 1196 px and 880 px square. Serving the
      6 # originals cost 530 KB and 127 KB a page, which was most of the front
      7 # page's weight.
      8 #
      9 # Originals stay in the repository: static/images/self.jpg is the source
     10 # for the avatar and static/images/self-tiny-white.png for the icons.
     11 # Neither is referenced by any page.
     12 set -eu
     13 
     14 cd "$(dirname "$0")/.."
     15 command -v magick >/dev/null || { echo "resize-images: need ImageMagick" >&2; exit 1; }
     16 
     17 # 2x the display size, which covers the retina screens this is likely
     18 # to be read on without paying for a denser one.
     19 magick static/images/self.jpg -resize 640x640 -strip -quality 75 \
     20 	-define webp:method=6 static/images/self.webp
     21 
     22 for size in 32 16; do
     23 	magick static/images/self-tiny-white.png -resize ${size}x${size} -strip \
     24 		static/images/favicon-$size.png
     25 done
     26 magick static/images/self-tiny-white.png -resize 180x180 -strip \
     27 	static/images/apple-touch-icon.png
     28 
     29 for f in self.webp favicon-32.png favicon-16.png apple-touch-icon.png; do
     30 	printf '  %-24s %7s bytes\n' "$f" "$(stat -c%s "static/images/$f")"
     31 done