Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Last active September 15, 2020 20:08
Show Gist options
  • Save sarkrui/36792bca98c28b31babaaf7ba5e5c2ef to your computer and use it in GitHub Desktop.
Save sarkrui/36792bca98c28b31babaaf7ba5e5c2ef to your computer and use it in GitHub Desktop.
Make GIFs and generate web URL
#!/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
@sarkrui
Copy link
Author

sarkrui commented Sep 15, 2020

Dependencies

  1. FFmpeg
  2. uPic

Add an alias in ~/.zshrc, so you will able to call all script globally as the demo shows.

alias mkgif="/path/to/script"

Demo


Spaces in the filename will be automatically replaced with underdashes.

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