Created
December 20, 2023 09:36
-
-
Save vondraussen/12765e5cf33ec7c1b2887deb54c03158 to your computer and use it in GitHub Desktop.
Canon CR2 RAW File to HEIC Conversion
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
#!/bin/bash | |
: ' | |
Description: Canon CR2 to HEIC Converter | |
This Bash script automates the process of converting Canon CR2 raw image files to High-Efficiency Image Format (HEIC) files with a 16-bit color depth. The conversion is achieved using `dcraw` for raw file processing, preserving the intricate details captured by Canon cameras. Additionally, `exiftool` is employed to extract and retain Exif metadata, ensuring valuable information about the images is maintained. | |
Features: | |
- Converts Canon CR2 raw files to HEIC format. | |
- Utilizes `dcraw` for high-quality raw file conversion. | |
- Preserves 16-bit color depth for enhanced image fidelity. | |
- Extracts and retains Exif metadata with the use of `exiftool`. | |
- Streamlines the process for batch conversion. | |
Usage: | |
1. Place your Canon CR2 raw files in the designated input directory (\$1). | |
2. Run the script, providing the input directory as the first argument: | |
' | |
# check if argument 1 is a folder | |
if [ ! -d "$1" ]; then | |
echo "Folder does not exist: $folder" | |
exit 1 | |
fi | |
# Create output directory if not exists | |
output_dir="$1/output_heic" | |
mkdir -p "$output_dir" | |
time { | |
# Convert raw files to jpeg using dcraw and ImageMagick | |
for raw_file in $1/*.CR2; do | |
base_name=$(basename "$raw_file" .CR2) | |
heic_file="$output_dir/${base_name}.heic" | |
if [ -e "$heic_file" ]; then | |
echo "Skipping conversion of $heic_file, file already exists." | |
continue | |
fi | |
# create 16bit heic image from raw file | |
dcraw -6 -m 2 -q 3 -o 1 -c -w "$raw_file" | convert -quiet -depth 16 -quality 60 - "$heic_file" | |
exiftool -q -overwrite_original -tagsfromfile "$1"/"$raw_file" -all:all "$heic_file" | |
echo "Converted: $raw_file to $heic_file" | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment