Created
April 22, 2023 16:33
-
-
Save perillamint/d53a8d3acd581cd9ff5db0e8f7b2d182 to your computer and use it in GitHub Desktop.
Toot picture with EXIF information!
This file contains hidden or 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
#!/bin/bash | |
set -e | |
# CONFIG ZONE | |
MASTODON_INSTANCE="social.silicon.moe" | |
MASTODON_AUTH_TOKEN="[REDACTED]" | |
FILE="$1" | |
if [ ! -f "$FILE" ]; then | |
echo "Usage: $0 [image file] [message]" | |
exit 1 | |
fi | |
if [ "$2" == "" ]; then | |
echo "Usage: $0 [image file] [message]" | |
exit 1 | |
fi | |
EXIF_JSON=$(exiftool -json $FILE | jq '.[0]') | |
# METADATA ZONE | |
EXIF_STR=$(echo $EXIF_JSON | jq -r '[ | |
.Make, " ", .Model, " / ", .LensID, ", ", | |
.ShutterSpeed, " f/", .FNumber, " ", .FocalLength, " ISO ", .ISO | |
] | @tsv' | sed 's/\t//g') | |
echo $EXIF_STR | |
# Encode image to AVIF (to compact) | |
RESIZED_IMG=$(mktemp) | |
WEBP_IMG="${RESIZED_IMG}.webp" | |
#AVIF_IMG="${RESIZED_IMG}.avif" | |
convert "$FILE" -resize 4096x4096 "$RESIZED_IMG" | |
cwebp "$RESIZED_IMG" -q 100 -o "$WEBP_IMG" | |
#avifenc -j $(nproc) --min 0 --max 5 -a tune=ssim "$RESIZED_IMG" "$AVIF_IMG" | |
MEDIA_JSON=$(curl -f -H "Authorization: Bearer $MASTODON_AUTH_TOKEN" -X POST -H "Content-Type: multipart/form-data" "https://$MASTODON_INSTANCE/api/v1/media" --form file="@$WEBP_IMG") | |
#MEDIA_JSON=$(curl -f -H "Authorization: Bearer $MASTODON_AUTH_TOKEN" -X POST -H "Content-Type: multipart/form-data" "https://$MASTODON_INSTANCE/api/v1/media" --form file="@$AVIF_IMG") | |
MEDIA_ID=$(echo "$MEDIA_JSON" | jq -r .id) | |
rm -f "$RESIZED_IMG" | |
rm -f "$WEBP_IMG" | |
#rm -f "$AVIF_IMG" | |
MESSAGE=$(printf "%s\n\n%s #사진토돈" "$2" "$EXIF_STR") | |
curl -f "https://$MASTODON_INSTANCE/api/v1/statuses" -H "Authorization: Bearer $MASTODON_AUTH_TOKEN" -F "status=$MESSAGE" -F "language=kor" -F "visibility=public" -F "media_ids[]=$MEDIA_ID" > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment