Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created January 26, 2019 20:00
Show Gist options
  • Select an option

  • Save ZGainsforth/1b5a0fc1d7944953dd15d1030b5e6c98 to your computer and use it in GitHub Desktop.

Select an option

Save ZGainsforth/1b5a0fc1d7944953dd15d1030b5e6c98 to your computer and use it in GitHub Desktop.
Shell script to crop and adjust resolution of images in pipeline
#!/bin/bash
extension=jpeg
function docrop {
mogrify -crop $1 $2.$extension
rm $2-1.$extension
mv $2-0.$extension $2.$extension
}
# Make the directories if they don't already exist.
! test -d $extension-hires && mkdir $extension-hires
! test -d $extension-lores && mkdir $extension-lores
echo Cleaning up first.
rm -f $extension-hires/*.xbb
rm -f $extension-lores/*.xbb
rm -f $extension-lores/*.$extension
rm -f *.xbb
rm -f *.$extension
echo Copying keynote output too hires
cd Images
ls -l *.$extension | awk '{print $9 " " substr($9, 8)}' | xargs -n 2 mv
cd ..
cp Images/* $extension-hires
cd $extension-hires
echo Cropping images.
# Particle 3 mosaic
docrop 4096x2048 021
# Particle 3 GEMS-like.
docrop 4096x3959 027
# Particle 3 GEMS-like phosphide planet.
docrop 4096x3959 028
# Particle 3 CU.
docrop 4096x3959 029
# Nessie overview.
docrop 4096x2051 034
# Humpty overview.
docrop 4096x2446 053
# Humpty EA3 LRGB.
docrop 4096x2665 062
cd ..
echo Copying files to low res dir...
cp $extension-hires/*.$extension $extension-lores
echo Reducing resolution in low res dir...
sips -Z 200 $extension-lores/*.$extension &> /dev/null
echo Extracting bounding boxes...
extractbb $extension-hires/*.$extension
extractbb $extension-lores/*.$extension
if [ "$1" != "lores" ]; then
echo Copying high resolution files to output...
cp $extension-hires/*.* ../Images
else
echo Copying low resolution files to output...
cp $extension-lores/*.* ../Images
fi
echo Done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment