Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Pondelok, 19. máj 2025

Súbor: [Platon] / scripts / shell / photo-managment / raw2jpeg (stiahnutie)

Revízia 1.1, Wed Aug 5 19:46:11 2009 UTC (15 years, 9 months ago) by rajo

Tool to convert RAW photo files to JPEG. Based on foto-copy script.

#!/bin/sh
#
# Description - convert RAW photos to JPEG with Exif
#
# Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
# Copyright (c) 2009-2009 Platon Group, http://platon.sk/
# Licensed under terms of GNU General Public License.
# All rights reserved.
#
# Changelog:
# 2009-08-05 - created
#

# $Platon: scripts/shell/photo-managment/foto-copy,v 1.3 2009-01-12 23:17:07 rajo Exp $

# howto rename your files: img_1234.jpg --> 2006-08-13_230001_img_1234.jpg (image taken on  2006-08-13 23:00:01)
JHEAD_OPTS="-n%Y-%m-%d_%H%M%S_%f"

# paths setup:
JHEAD="jhead"
DCRAW="dcraw"
EXIV2="exiv2"
PPMTOJPEG="ppmtojpeg"

# lossless rotation of JPEG files
do_rotation()
{ # {{{
    rrfile="$1"
    degres="$2"

    echo -e "\t--> rotating $degres $rrfile"
    if jpegtran -rotate $degres -copy all -outfile ${rrfile}_tmp ${rrfile};
    then
        echo -e "\t\tRotated"
        mv ${rrfile}_tmp ${rrfile}
        $EXIV2 -M'del Exif.Image.Orientation' $rrfile
    else
        echo -e "\t\tFailed"
        rm ${rrfile}_tmp
    fi
} # }}}

# distinguish angle of rotation
rotate_jpeg()
{ # {{{
    rfile="$1"

    orient=`$EXIV2 -P kyv $rfile | awk '/Exif.Image.Orientation/ { print $3; }'`
    case "$orient" in
        1)    echo "$rfile: Orientation: $orient top left";
            ;;
        6)    echo "$rfile: Orientation: $orient right top";
            do_rotation $rfile 90
            ;;
        8)    echo "$rfile: Orientation: $orient left bottom";
            do_rotation $rfile 270
            ;;
        *)    echo "$rfile: Orientation: $orient UNKNOWN";
            ;;
    esac
} # }}}

for i in $*; do # {{{
    [ "x$i" = "x*.crw" ] && continue
    [ "x$i" = "x*.cr2" ] && continue
    file=${i%.crw}
    file=${file%.cr2}
    if [ ! -f "$file.jpg" ]; then
        echo --- $i;
        $DCRAW -w $i # use white ballance set by camera
        $PPMTOJPEG $file.ppm > $file.jpg && rm -f  $file.ppm ;
    fi

    # set EXIF information:
    rm -f $file.exv $file-thumb.jpg
    $EXIV2 ex $i
    [ -f $file.thm ] && ln -s $file.thm $file-thumb.jpg

    # doesn't work correctly
    #$EXIV2 -it $file.thm $file.jpg
    # use Exif info from *.thm file otherwise from *.crw file
    if [ -f "$file.thm" ]; then
        $EXIV2 -P kyv $file.thm | awk 'NF > 2 { print; }' | sed 's/^/set /g;' > $file.cmd
    else
        $EXIV2 -P kyv $i | awk 'NF > 2 { print; }' | sed 's/^/set /g;' > $file.cmd
    fi
    $EXIV2 -m $file.cmd $file.jpg

    # fix: Canon EOS 300D Digital Rebel stores wrong Exif.Image.Orientation info *.thm files
    # Exif.Image.Orientation needs to be read from RAW image
    #$EXIV2 -P kyv $file.crw | awk '/Exif.Image.Orientation/ { print; }' | sed 's/^/set /g;' > $file.cmd
    #$EXIV2 -m $file.cmd $file.jpg

    # rotate image if needed - we don't need rotate this JPEG file, because
    # orientation will be fixed if Exif.Image.Orientation Exif tag is removed.
    #rotate_jpeg $file.jpg

    # remove incorrect Exif headers (taken from thumbnail or after rotation)
    $EXIV2 \
        -M'del Exif.Image.XResolution' \
        -M'del Exif.Image.YResolution' \
        -M'del Exif.Image.Orientation' \
        $file.jpg

    # rename
    $JHEAD $JHEAD_OPTS $file.jpg

    # cleanup
    rm -f $file-thumb.jpg
    rm -f $file.exv
    rm -f $file.cmd

done # }}}

# vim: fdm=marker fdl=0 fdc=3


Platon Group <platon@platon.sk> http://platon.sk/
Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok