| #!/bin/bash |
| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| ### Takes a screenshot and copies it to the host. |
| |
| ## usage: fx screenshot [--trim] [--png] [-o <screencap_file>] |
| ## |
| ## This command invokes Fuchsia's screencap tool to create a screenshot. |
| ## The result is written to screencap.ppm or screencap.png. To write to |
| ## another filename, use the -o parameter. |
| ## The --trim and --png commands require ImageMagick to be installed. |
| ## Unrecognized parameters will be passed to ssh. |
| ## |
| ## Example usage: |
| ## |
| ## fx screenshot --trim --png |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"/lib/vars.sh |
| fx-config-read |
| |
| OUT=screencap.ppm |
| png_command=cat |
| enable_trim=0 |
| while [[ $# -ne 0 ]]; do |
| case $1 in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| -o|--out) |
| shift |
| OUT=$1 |
| ;; |
| --png) |
| OUT=${OUT%.*}.png |
| png_command=pnmtopng |
| ;; |
| --trim) |
| enable_trim=1 |
| ;; |
| *) |
| break |
| ;; |
| esac |
| shift |
| done |
| |
| fx-command-run shell "$@" screencap | $png_command > "$OUT" |
| if [[ $enable_trim -ne 0 ]]; then |
| mogrify -trim +repage $OUT |
| fi |
| |