58 lines
2.1 KiB
Django/Jinja
58 lines
2.1 KiB
Django/Jinja
#!/bin/bash
|
|
# no need to do this math forever
|
|
input_width=1920
|
|
input_height=1080
|
|
output_width=1340
|
|
output_height=580
|
|
# Calculate the ratio for trimming the top part
|
|
trim_ratio=$(echo "scale=4; $output_height / $output_width * $input_width" | bc)
|
|
|
|
# this saves a snapshot of the camera every second or so depending on how long all the other crap takes
|
|
# let's hope the vars make it otherwise imma need to parse a bollocksing file
|
|
|
|
i=1
|
|
while [ -f "$WORKING_DIR/run" ]
|
|
do
|
|
FILENAME=$(printf "img-%05d" "$i")
|
|
LATLON=$(curl -s http://10.18.1.1:8184/where_is?api_key={{ tesla_api_key }} )
|
|
LON=$(echo $LATLON | jq .lon)
|
|
LAT=$(echo $LATLON | jq .lat)
|
|
COORDINATES="$LAT, $LON"
|
|
curl http://127.0.0.1:7123/snapshot --output $WORKING_DIR/$FILENAME.jpg
|
|
|
|
# This variable is for the timestamp
|
|
TIME=$(date +%c)
|
|
|
|
# this big boi should add both the timestamp and the coordinates
|
|
convert $WORKING_DIR/$FILENAME.jpg \( +clone -gravity NorthWest -pointsize 22 -fill yellow -annotate +30+30 "$TIME" \) \
|
|
\( +clone -gravity NorthEast -pointsize 22 -fill yellow -annotate +30+30 "$COORDINATES" \) \
|
|
-append $WORKING_DIR/$FILENAME.jpg
|
|
|
|
# This is for the tiny pic
|
|
# I'll make one every 5 seconds
|
|
# I have 1340x580. i think i will truncate the top
|
|
# Calculate the height to trim based on the aspect ratios of the input and output images
|
|
if (( $i % 5 == 0 )); then
|
|
NOW=$(date +%Y%m%d%H%M%S)
|
|
convert $WORKING_DIR/$FILENAME.jpg -gravity North -crop x$trim_ratio +repage -resize 1340x580 {{ working_folder }}/small_thumbs/$NOW.jpg
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
((i++))
|
|
|
|
done
|
|
|
|
|
|
# old one-at-a-time rubbish
|
|
# # This should add the current time to the image and save it
|
|
# convert $WORKING_DIR/$FILENAME.jpg -gravity NorthWest -pointsize 22 \
|
|
# -fill yellow -annotate +30+30 $TIME $WORKING_DIR/$FILENAME-temp.jpg
|
|
# # Delete original
|
|
# rm $WORKING_DIR/$FILENAME.jpg
|
|
#
|
|
# # This should add the current latlon to the image and save it
|
|
# convert $WORKING_DIR/$FILENAME-temp.jpg -gravity NorthEast -pointsize 22 \
|
|
# -fill yellow -annotate +30+30 $COORDINATES $WORKING_DIR/$FILENAME.jpg
|
|
# # Delete temp
|
|
# rm $WORKING_DIR/$FILENAME-temp.jpg |