Initial push
[termux-packages] / packages / termux-api / termux-camera-photo
CommitLineData
59f0d218
FF
1#!/system/bin/sh
2
3set -e -u
4
5SCRIPTNAME=$0
6show_usage () {
7 echo "usage: $SCRIPTNAME [OPTIONS] <output-file>"
8 echo ""
9 echo "Take a photo and save it in a file. Valid options:"
10 echo " -c, --camera <camera-id> the id of the camera to use"
11 echo "See the termux-camera-info for getting information about available cameras"
12}
13
14PARAM_CAMERA=""
15PARAM_SIZE=""
16O=`getopt -l camera: -l help -l size -- c:hs: "$@"`
17eval set -- "$O"
18while true; do
19case "$1" in
20 -c|--camera) PARAM_CAMERA="--ei camera $2"; shift 2;;
21 -h|--help) show_usage; exit 0;;
22 -s|--size) PARAM_SIZE="--ei size_index $2"; shift 2;;
23 --) shift; break;;
24 *) echo Error; exit 1;;
25esac
26done
27
28touch $1
29FILE=`realpath $1`
30
31# Output is like:
32# Broadcasting: Intent { cmp=com.termux.extras/.SmsLister }
33# Broadcast completed: result=13, data="http://fornwall.net"
34OUTPUT=`LD_LIBRARY_PATH= am start --user 0 $PARAM_CAMERA $PARAM_SIZE --es file $FILE -n com.termux.extras/.PhotoActivity | grep result=1 | cut -d ' ' -f 4`
35
36if [ $? != "0" ]; then
37 echo "ERROR: Failed, see logs"
38 exit 1
39fi