Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fastest image converter on osx
# 2015 Stefan Crain -
# Find all image files and convert them to a jpgs with sips
# OSX only
# Usage
# ./ toScan/ Output/
threads=${parsedCLI[2]:-`sysctl -n hw.ncpu`}
if [ -z "$scandir" ]; then printf "\033[35;1mIncorrect Usage,Try\n\033[0m./ /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