Skip to content

Instantly share code, notes, and snippets.

@wormyrocks
Last active March 19, 2023 06:35
Show Gist options
  • Save wormyrocks/15f9244131d50e1f1a157940ca8146c8 to your computer and use it in GitHub Desktop.
Save wormyrocks/15f9244131d50e1f1a157940ca8146c8 to your computer and use it in GitHub Desktop.
macOS script to use exiftool to extract depth from iPhone JPG, HEIC images
#!/bin/bash
PATH=$PATH:/usr/local/bin
checkdep(){
command -v $1 && return
msg="Please install Homebrew by visiting https://brew.sh."
[[ "$1" == "brew" ]] || msg="Please install ${1} with 'brew install ${1}'."
osascript -e "tell app \"System Events\" to display dialog \"$msg\""
exit 0
}
checkdep brew
checkdep exiftool
checkdep heif-convert
mkdir -p /tmp/extracted
trympimg(){
outfile="/tmp/extracted/$(basename "$1")-MPImage${2}.jpg"
exiftool "$1" -b -MPImage"${2}" > "$outfile"
[[ -s "$outfile" ]] || {
rm "$outfile"
[[ "$2" -gt "2" ]] && {
return 0
}
return 1
} && trympimg "$1" $(($2+1))
}
tryheic(){
outfile="/tmp/extracted/$(basename "$1").jpg"
heif-convert -q 100 "$1" "$outfile"
}
tried=0
success=0
for f in "$@"
do
tried=$((tried+1))
trympimg "$f" 2 && cp "$f" /tmp/extracted || tryheic "$f" && success=$((success+1))
done
msg="Done. Tried ${tried} files, ${success} of them were successful."
osascript -e "tell app \"System Events\" to display dialog \"$msg\""
[[ "$success" -gt 0 ]] && open /tmp/extracted
@wormyrocks
Copy link
Author

Here it is packaged as a .app file. (Drag and drop images to use)
Still requires exiftool and libheif to be installed through Homebrew.
https://www.dropbox.com/s/vv2xnnap32a7qvq/exiftool_extract.zip?dl=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment