Skip to content

Instantly share code, notes, and snippets.

@stefancrain
Created February 14, 2015 00:39
Show Gist options
  • Save stefancrain/08ec5ff5bd7acd1d6e31 to your computer and use it in GitHub Desktop.
Save stefancrain/08ec5ff5bd7acd1d6e31 to your computer and use it in GitHub Desktop.
Fastest image converter on osx
#!/bin/bash
# 2015 Stefan Crain - [email protected]
# Find all image files and convert them to a jpgs with sips
# OSX only
#
# Usage
# ./convert.sh toScan/ Output/
parsedCLI=("$@")
scandir=${parsedCLI[0]%/}
outputdir=${parsedCLI[1]:-$scandir}
outputdir=${outputdir%/}
threads=${parsedCLI[2]:-`sysctl -n hw.ncpu`}
if [ -z "$scandir" ]; then printf "\033[35;1mIncorrect Usage,Try\n\033[0m./convert.sh /toScan/ /Output/" && exit 1; fi
echo "Processing images from '"$scandir"' to '"$outputdir"' "$threads" at a time"
mkdir -p "$outputdir"
cd "$scandir"
start_time=`date +%s`
file * | grep " image data" | cut -d: -f1 | # find files with image data within folder
sed "s#\(.*\)#\\1 $outputdir/\\1#g" | # modify string to repeat filename and include $outputdir
sed "s/\.[^.]*$/.jpg/g" | # replace final extension with jpg
awk '{print ""$1" --out "$2}' | # use modified string to place created files in $outputdir
xargs -P$threads -L1 -n3 sips -s format jpeg > /dev/null 2>&1 # use all cores > don't display output
echo -e "\033[35;1mCreating jpg files took: "`expr $(date +%s) - $start_time`" Seconds\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment