Last active
December 15, 2015 14:58
-
-
Save dsdstudio/5277835 to your computer and use it in GitHub Desktop.
RAW ImageFile to jpeg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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