Skip to content

Instantly share code, notes, and snippets.

@salopst
Created October 4, 2018 15:20
Show Gist options
  • Save salopst/30aa0c0175c8b80a14d918c3db6db440 to your computer and use it in GitHub Desktop.
Save salopst/30aa0c0175c8b80a14d918c3db6db440 to your computer and use it in GitHub Desktop.
use imagemagik to resize to longest axis
#!/bin/bash
#
# 2018-10-04
# yearlux@xolotl
#
# use imagemagik to resize to longest axis
if [[ `uname` == 'Darwin' ]]
then
echo "OS X"
if ! [ -x "$(command -v rename)" ]; then
echo 'Error: rename is not installed... first run "brew install rename"' >&2
#fuck it... it's just me anyway
`brew install rename`
exit 1
fi
fi
FILES="$(find . -name '*' -exec file {} \; | grep -oi '^.*image' | cut -d':' -f1)"
ORIGINALS_DIR="originals"
PX=$1
if [[ -z $PX ]]; then
echo "usage: "
echo "./resize-la.sh int_no_pixels"
echo "for example: "
echo "./resize-la.sh 800"
echo "will resize images in `pwd`, the longest axis being 800px"
echo "copies will be saved in `pwd`/${ORIGINALS_DIR}"
fi
mkdir $ORIGINALS_DIR
for f in $FILES; do cp $f ./$ORIGINALS_DIR; done
rename 's/\s/_/' *
rename 's/\.jpeg$/.jpg/' *
for f in $FILES
do
cp $f ./$ORIGINALS_DIR
# convert ${f} output/`printf "%06X"`.jpg
convert ${f} -resize "${PX}>" ${f}-${PX}-pxla.jpg
#echo `exiftool ${f} | grep size -i`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment