Skip to content

Instantly share code, notes, and snippets.

@JasonThomasData
Created January 21, 2021 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JasonThomasData/2467fbf2f49f5af391e396fd5b201fbf to your computer and use it in GitHub Desktop.
Save JasonThomasData/2467fbf2f49f5af391e396fd5b201fbf to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
############################################
## This program converts a directory of .NEF images to jpeg, png or TIFF format.
## It also resizes the images
##
## Examples:
## ./FILENAME FORMAT WIDTH_RESIZE
## ./batchConvertNEF.sh png 500
## ./batchConvertNEF.sh jpeg
outputExtensionOptions=(jpeg tiff png) #Check the convert -h docs for available save options, if not an option, resorts to dcraw type
outputFileExtension=$1
if [[ -z "$outputFileExtension" ]]; then
echo "need output param, eg: $0 <jpeg|png|tiff>"
exit 1
fi
if [[ ! ${outputExtensionOptions[*]} =~ $outputFileExtension ]]; then
echo "valid outputs are: ${outputExtensionOptions[*]}"
exit 1
fi
echo "Saving NEF files as $outputFileExtension"
outputImageWidth=$2
if [[ -n "$outputImageWidth" ]]; then
echo "Images will be made $outputImageWidth px wide"
else
echo "To resize image, do: $0 <jpeg|png|tiff> <output width in px>"
fi
for fileName in $(ls)
do
if [[ $fileName != *".NEF" ]]; then
continue
fi
echo $fileName
if [[ -z "$outputImageWidth" ]]; then
dcraw -c $fileName | convert - "$fileName.$outputFileExtension"
else
dcraw -c $fileName | convert - -scale $outputImageWidth "$fileName.$outputFileExtension"
fi
done
@JasonThomasData
Copy link
Author

For my future reference, this is what my Nikon camera produces... NEF format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment