Last active
September 15, 2020 20:08
-
-
Save sarkrui/36792bca98c28b31babaaf7ba5e5c2ef to your computer and use it in GitHub Desktop.
Make GIFs and generate web URL
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 | |
scriptname="makgif" | |
FILEPATH=$1 | |
FILENAME=$(basename "$FILEPATH") | |
EXTENSION="${FILENAME##*.}" | |
NULLPATH=${FILEPATH%/*} | |
OUTPUTNAME=$(echo "$FILENAME".gif | sed "s/ /_/g" | sed "s/.$EXTENSION//g") | |
NULLPATH=${FILEPATH%/*} | |
RED='\033[0;31m' | |
NC='\033[0m' # No Color | |
function debug(){ | |
echo "##################### Debug Message ####################" | |
echo "########################################################" | |
echo "$FILEPATH" | |
echo "$FILENAME" | |
echo "$EXTENSION" | |
echo "$NULLPATH" | |
echo "$OUTPUTNAME" | |
echo "########################################################" | |
} | |
#debug | |
OUTPUTPATH=$NULLPATH/$OUTPUTNAME | |
ffmpeg -hide_banner -loglevel warning -pix_fmt rgb8 -r 17 -y "$OUTPUTPATH" -i "$FILEPATH" | |
if [ -e "$OUTPUTPATH" ]; then | |
echo "File found!"; | |
FILESIZE=$(stat -f%z "$OUTPUTPATH") | |
MEGABYTE=$(($FILESIZE / 1048576)) | |
echo "Size pf $OUTPUTNAME = $MEGABYTE MB." | |
if [[ "$FILESIZE" -lt 20971520 ]]; then | |
echo "File size smaller than 20MB!" | |
echo "Uploading to imgur......"; | |
/Applications/uPic.app/Contents/MacOS/uPic -s -u "$OUTPUTPATH"| tail -n -1 | pbcopy; | |
printf "${RED}$(pbpaste)${NC} Exported!\n"; | |
echo "imgur url copied!" | |
open $(pbpaste); | |
#rm $OUTPUTPATH | |
else | |
echo "File size too large!"; | |
fi | |
else | |
echo "File does not exist"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dependencies
Add an alias in ~/.zshrc, so you will able to call all script globally as the demo shows.
Demo
Spaces in the filename will be automatically replaced with underdashes.