render-header.sh

main
appstore-kit/render-header.sh history · blame · raw

63 lines · 2670 bytes · executable

1 symbol in this file
 1#!/bin/sh
 2# Renders an app's product page header: three iPhone screenshots fanned over a background, as
 3# header-21x9.png (3840x1646) and header-16x9.png (5244x2950), with headless Chromium and the
 4# alpha channel removed.
 5# Usage: render-header.sh <AppStore directory>
 6# The directory holds screenshots/iphone-6.9/ and header.conf, which sets:
 7#   background  the CSS background
 8#   left center right  the screenshots' names in screenshots/iphone-6.9, without .png
 9#   extra_css   optional: CSS after the shared rules
10#   CHROMIUM    the Chromium binary (default /Applications/Chromium.app/Contents/MacOS/Chromium)
11set -eu
12
13dir="$(cd "${1:?usage: render-header.sh <AppStore directory>}" && pwd)"
14extra_css=
15. "$dir/header.conf"
16chromium="${CHROMIUM:-/Applications/Chromium.app/Contents/MacOS/Chromium}"
17page="$dir/.header.html"
18trap 'rm -f "$page"' EXIT
19
20cat > "$page" <<HTML
21<!doctype html>
22<html>
23<head>
24<meta charset="utf-8">
25<style>
26  :root { --u: 1px; --top: 180px; }
27  * { box-sizing: border-box; }
28  html, body { margin: 0; width: 3840px; height: 1646px; overflow: hidden; }
29  body { position: relative; background: $background; }
30  .iphone {
31    position: absolute; left: 50%; top: var(--top);
32    width: calc(860 * var(--u)); height: calc(1868 * var(--u));
33    padding: calc(24 * var(--u)); border-radius: calc(140 * var(--u)); background: #0c0c12;
34    box-shadow: 0 calc(50 * var(--u)) calc(120 * var(--u)) rgba(0, 0, 0, 0.5);
35  }
36  .iphone img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: top; border-radius: calc(116 * var(--u)); }
37  .center { transform: translateX(-50%); z-index: 2; }
38  .left { transform: translate(calc(-50% - 760 * var(--u)), calc(120 * var(--u))) rotate(-8deg); }
39  .right { transform: translate(calc(-50% + 760 * var(--u)), calc(120 * var(--u))) rotate(8deg); }
40
41  /* 16:9, 5244x2950. */
42  html.wide { --u: 1.6px; --top: 420px; }
43  html.wide, .wide body { width: 5244px; height: 2950px; }
44$extra_css
45</style>
46<script>if (location.hash === "#wide") document.documentElement.className = "wide";</script>
47</head>
48<body>
49  <div class="iphone left"><img src="screenshots/iphone-6.9/$left.png"></div>
50  <div class="iphone right"><img src="screenshots/iphone-6.9/$right.png"></div>
51  <div class="iphone center"><img src="screenshots/iphone-6.9/$center.png"></div>
52</body>
53</html>
54HTML
55
56render() {
57    "$chromium" --headless --hide-scrollbars --force-device-scale-factor=1 --window-size="$2" \
58        --screenshot="$dir/$1" "file://$page$3" 2>/dev/null
59    magick "$dir/$1" -alpha off "PNG24:$dir/$1"
60    echo "wrote $dir/$1"
61}
62render header-21x9.png 3840,1646 ""
63render header-16x9.png 5244,2950 "#wide"