-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpanofyForFacebook
executable file
·45 lines (38 loc) · 1.32 KB
/
panofyForFacebook
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env bash
# Adds metadata to images so that Facebook displays them as panoramas.
# https://discuss.pixls.us/t/panorama-mode-in-facebook/3585
# By Harry Durgin and Morgan Hardwood
if [[ ! -f ${1} ]]; then
printf '%s\n' "No input file specified or file not found." "Aborting."
exit 1
fi
hfov=0
while [[ hfov -lt 100 || hfov -gt 360 ]]; do
read -r -p "Enter horizontal field of view (100-360): " hfov
done
for f in "${@}"; do
printf '%s\n' "" "Processing: $f"
width="$(exiftool -T -ImageWidth "${f}")"
height="$(exiftool -T -ImageHeight "${f}")"
ratio=$((width/height))
if [[ ratio -lt 2 ]]; then
printf '%s\n' "Image must have a ratio of at least 2:1." "Skipping."
continue
fi
width_full=$((360*width/hfov))
height_full=$((180*width_full/hfov))
height_full=$((width_full/2))
left_crop=$(((width_full-width)/2))
top_crop=$(((height_full-height)/2))
exiftool \
-overwrite_original \
-FullPanoWidthPixels="$width_full" \
-FullPanoHeightPixels="$height_full" \
-CroppedAreaLeftPixels="$left_crop" \
-CroppedAreaTopPixels="$top_crop" \
-CroppedAreaImageWidthPixels="$width" \
-CroppedAreaImageHeightPixels="$height" \
-ProjectionType=equirectangular \
-UsePanoramaViewer=True \
"$f"
done