Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
RAW ImageFile to jpeg
#!/usr/bin/env bash
###########################################
# RAW Image to jpeg conversion script #
# for Mac OSX #
# author : <Bohyung kim> dsdgun@gmail.com #
###########################################
__pwd="${PWD}"
__exec_sips=`which sips`
__rawfile_pattern="nef|cr2|rw2"
__convert_format=jpeg
__output_dir_suffix=output
__output_dir="${__pwd}/${__output_dir_suffix}"
__log() {
echo "$*"
}
__clear_output_dir() {
__log "got interrupted.."
__log "clear outputdir : ${__output_dir}"
rm -rf "${__output_dir}"
exit 0
}
__mkdir() {
mkdir -p "$*"
}
__convert() {
_filelist=$(ls | egrep -i "$__rawfile_pattern")
if [ ! -d "${__output_dir}" ]; then
__mkdir "${__output_dir}"
fi
for i in $_filelist;
do
sips -s format "${__convert_format}" $i --out "${__output_dir}/${i%.*}.jpg"
done
}
__check_env() {
if [ -z $__exec_sips ]; then
__log "envcheck failed : sips does not exist"
exit 1
fi
if [ ! -w ${__pwd} ]; then
__log "envcheck failed : Write permiss is not granted to ${__pwd}"
exit 1
fi
}
__main() {
__check_env
__convert
}
# Ctrl + c 로 종료한경우 _outputdir 정리
trap "{ __clear_output_dir; }" SIGINT SIGTERM
__main "$*"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment