-
-
Save almoorthi/8ac4ad843b4d1e28a0d13595d10a27e5 to your computer and use it in GitHub Desktop.
img-url-exif.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Josh Skidmore <[email protected]> | |
# Basic example of using an HTTP range header to extract EXIF data | |
# from a JPEG file without having to download the entire image. | |
# This has no error handling and assumes the EXIF data is embedded | |
# within the first $KB_TO_DOWNLOAD kilobytes of the image | |
# Requirements: | |
# * curl | |
# * exiftool | |
# Example JPEGs: | |
# https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Ricoh_Caplio_RR330.jpg | |
# https://live.staticflickr.com/3866/14356072311_4ef21a1001_o_d.jpg | |
[[ -z "$1" ]] && \ | |
echo "Usage: $(basename $0) [JPEG_URL]" && \ | |
exit | |
IMG_URL=$1 | |
KB_TO_DOWNLOAD=100 | |
B_TO_DOWNLOAD=$((KB_TO_DOWNLOAD*1024)) | |
TMP_DIR=$(mktemp -d) | |
TMP_IMG=$TMP_DIR/temp.jpg | |
THU_IMG=$TMP_DIR/thumbnail.jpg | |
EXIF_DUMP_FILE=$TMP_DIR/exif.txt | |
# grab the image with a range query | |
curl -s -o $TMP_IMG --header "Range: bytes=0-${B_TO_DOWNLOAD}" $IMG_URL | |
# (debugging) determine exif starting byte range | |
exif_starting_byte=$(cat $TMP_IMG | grep -a -bo Exif | cut -d : -f 1) | |
# extract exif data | |
exif_data=$(exiftool $TMP_IMG) | |
# dump exif to file | |
echo -e "$exif_data" > $EXIF_DUMP_FILE | |
# dump exif to console | |
echo "#### START EXIF ####" | |
echo -e "$exif_data" | |
echo "#### END EXIF ####" | |
echo | |
echo "Image URL: $IMG_URL" | |
echo "Bytes Transferred: $B_TO_DOWNLOAD" | |
echo "EXIF Starting Marker Byte: $exif_starting_byte" | |
echo "EXIF Dump: $EXIF_DUMP_FILE" | |
# if an exif thumbnail is available, extract | |
[[ "$exif_data" =~ Thumbnail ]] && \ | |
exiftool -b -ThumbnailImage $TMP_IMG > $THU_IMG && \ | |
echo "Extracted Thumbnail: $THU_IMG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment