Skip to content

Instantly share code, notes, and snippets.

@dash17291
Created November 20, 2012 18:11
Show Gist options
  • Save dash17291/4119747 to your computer and use it in GitHub Desktop.
Save dash17291/4119747 to your computer and use it in GitHub Desktop.
#!/bin/bash
MAXW=800
GETW="%w"
SOURCE=""
TARGETDIR="$HOME/upload/public"
LINKS="$HOME/.publish/links.js"
TARGET=""
FNAME=""
FORCE=""
PRESERVE=""
SUBDIR=""
OPTION="-auto-orient"
## publish <files>
#publish -ccw <file>
#publish -cw <file>
if [ ${#} -lt 1 ]
then
echo "Usage: publish [options] <image>"
echo ""
echo "Options: -cw rotate clockwise"
echo " -ccw rotate counterclockwise"
echo " -d <dir> publish to a subdirectory"
echo " -as <name> set target filename (extension is the same as the source)"
echo " -f force (never prompt)"
echo " -p preserve size"
echo ""
exit 1
fi
while [ ${#} -gt 0 ]
do
if [ "$1" = "-d" ]
then
SUBDIR="$2"
shift 2
elif [ "$1" = "-cw" ]
then
OPTION="-rotate 90"
GETW="%h"
shift 1
elif [ "$1" = "-ccw" ]
then
OPTION="-rotate 270"
GETW="%h"
shift 1
elif [ "$1" = "-as" ]
then
FNAME="$2"
shift 2
elif [ "$1" = "-p" ]
then
PRESERVE=1
shift 1
elif [ "$1" = "-f" ]
then
FORCE=1
shift 1
else
if [ ! "$SOURCE" ]
then
SOURCE="$1"
fi
shift 1
fi
done
if [ "$FNAME" ]
then
FNAME=${FNAME}.${SOURCE##*.}
else
FNAME=$(basename "$SOURCE")
fi
TARGETDIR=${TARGETDIR}/${SUBDIR}${SUBDIR:+/}
TARGET=${TARGETDIR}${FNAME}
H=0
W=0
$(identify -format "let W=$GETW" "$SOURCE" 2>/dev/null)
if [ ${?} = 0 ]
then
if [ ${W} -gt ${MAXW} -a ! "$PRESERVE" ]
then
OPTION="$OPTION -resize $MAXW"
fi
if [ -e "$TARGET" -a ! "$FORCE" ]
then
echo -n "File already exists! Overwrite? y/[n] "
read answer
if [ "${answer:-n}" != "y" ]
then
exit 2
fi
fi
mkdir -p "$TARGETDIR"
convert ${OPTION} "$SOURCE" "$TARGET"
cd "$TARGETDIR"
URL=$(dropbox puburl "$FNAME")
DESC=$(date +"%F %H:%M")
echo 'links.push({"desc":"'"$DESC"'", "src":"'"$URL"'"})' >> "$LINKS"
echo "$URL"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment