From ca54663bcfc9a1c99cb65ee9a473ccd7db7a9c54 Mon Sep 17 00:00:00 2001 From: Alex Ives Date: Mon, 23 May 2016 19:38:04 -0500 Subject: [PATCH] Initial commit of the slackgmote --- README.md | 12 ++++++++++++ bin/slackgmote.sh | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 README.md create mode 100755 bin/slackgmote.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..823e67f --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +# Slackgmote + +Slackgmote is a small utility that depends on imagemagic and converts animated gifs to slack emoji. +It supports cropping them as well. Output will always meet slack standards and be named: +`original_name_crop_slack.gif` + +It is currently poorly written, not efficient, and has no tests. Feel free to re-write this in some +better way (like as a gem or something) and open a merge request. Or not. Whatever. + +## Usage + +`slackgmote path/to/gif.gif [WidthxHeight+offset+offset]` \ No newline at end of file diff --git a/bin/slackgmote.sh b/bin/slackgmote.sh new file mode 100755 index 0000000..e21a591 --- /dev/null +++ b/bin/slackgmote.sh @@ -0,0 +1,25 @@ +#! /bin/bash + +function usage { + echo Usage: $BASH_SOURCE gif.gif [crop SizeXxSizeY+OffsetX+OffsetY, ex: 120x120+10+10] + exit 1 +} + +img=$(echo $1 | sed 's/\.gif//') +crop=$2 + +max_wh=128 +max_size=64000 + +if [[ -z $1 ]]; then + usage +fi + +if [[ $crop ]]; then + convert ${img}.gif -coalesce -repage 0x0 -crop ${crop} +repage ${img}_crop.gif || usage + img=${img}_crop +fi +while [[ ! -e ${img}_slack.gif ]] || [[ $(ls -l ${img}_slack.gif | grep -o ' \d\d\d\d\d ' || echo 9999999) -gt $max_size ]]; do + convert -resize ${max_wh}x${max_wh} ${img}.gif ${img}_slack.gif + ((--max_wh)) +done \ No newline at end of file