Results 1 to 7 of 7

Thread: Command line geek question

  1. #1
    Join Date
    Apr 2008
    Location
    Toronto, Canada
    Beans
    28
    Distro
    Ubuntu Studio 9.10 Karmic Koala

    Command line geek question

    Greetings Ubuntu Users,

    Is there a way to convert raw image files in a folder to jpeg files? There are loads of pictures I took with a Canon camera that saves them as .crw which gimp has trouble with. I want to convert them to jpeg so I can work with them easier.

    Anyone know?

    -i-
    "SO we bide our time, waiting for a purer kick to bloom... &the future is still bleak, uncertain and beautiful..." -GSYBE

  2. #2
    Join Date
    May 2007
    Beans
    7,032
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Command line geek question

    The "convert" command (part of the imagemagick utility suite) can do this, so long as both formats are supported. Camera raw isn't specifically mentioned in the man page, but may be supported.

    The syntax is easy:
    Code:
    convert image.gif image.jpg
    I am aware of all internet traditions. | Getting the best help | Text formatting codes | My last.fm profile
    Should I PM support questions? NO!

  3. #3
    Join Date
    Mar 2008
    Beans
    4,714
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Command line geek question

    If imagemagick does not support your type of raw format, then do this:

    Install imagemagick and dcraw:
    Code:
    sudo apt-get install imagemagick
    sudo apt-get install dcraw
    The command to convert img_2539.cr2 to img_2539.jpg would be:

    Code:
    dcraw -Tc img_2539.cr2 | convert tiff:- img_2539.jpg
    The dcraw command outputs a tiff file. The 'convert' app converts the tiff data to jpg.

  4. #4
    Join Date
    Jul 2007
    Beans
    85
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Command line geek question

    You need to have the dcraw, cjpeg and exiftool programs installed:

    Code:
    sudo apt-get install libimage-exiftool-perl libjpeg-progs dcraw
    Then create the directory ~/bin and create a file named crw2jpeg-script.bash in it and make it executable.
    Code:
    mkdir ~/bin
    cd ~/bin
    touch crw2jpeg-script.bash
    chmod +x crw2jpeg-script.bash
    Then open the file in a text editor and paste the following contents in it:

    Edit: This version of the script will get confused by special characters etc. A better version is posted in this thread as post # 6. Please use that version. All other usage details remain the same.
    Code:
    #!/bin/bash
    DCRAW="dcraw -w -c "
    
    
    while [ $# -ge 1 ]
    do
    
    targetdir=$1
    
    for rawfile in $targetdir/*.[cC][rR][wW]
    
    do
        	
        OJPEG=$(echo $rawfile| perl -pe 's/\.crw$//i' | tr 'A-Z' 'a-z')'.jpeg'
        echo "${DCRAW} $rawfile | cjpeg > ${OJPEG}"
        ${DCRAW} -q 3 $rawfile | cjpeg -quality 100 > ${OJPEG} || echo " *PROBLEM*"
        # transfer EXIF data from the original raw file
        exiftool -overwrite_original -TagsFromFile "$rawfile" "${OJPEG}" >/dev/null
        # preserve timestamps as much as possible
        # touch -r "$rawfile" "${OJPEG}"
        dcraw -z "${OJPEG}"
    
        # UNCOMMENT to delete raw files:
        # rm -f $rawfile
    
    done
        shift
        
    done
    This script uses raw files to create equivalent high quality jpegs with same exif data. It can also delete the original raw files if you uncomment the relevant line in it.

    bash ~/bin/crw2jpeg-script dir1 dir2 dir3 should create jpeg files for raw files in dir1, dir2 and dir3.
    Last edited by sarang; December 20th, 2008 at 11:10 PM.

  5. #5
    Join Date
    Apr 2008
    Location
    Toronto, Canada
    Beans
    28
    Distro
    Ubuntu Studio 9.10 Karmic Koala

    Re: Command line geek question

    Hello Repliers,

    First thanks to p_quarles and Unutbu--I have figured out how to convert .CRW files to .TIFF files. Then I converted them to .JPEG's

    I was wondering if there was a way to skip the TIFF files and go straight to jpeg.

    To facilitate the ease of plugin use I installed the Ubuntu studio graphic suite.

    Now Sarang's response is intriguing, it seems to skip the TIFF process. I am just worried about re-installing things I might already have. Let me give Sarang's proccess a try and then I will get back to ye.

    Thanks!

    -I-
    "SO we bide our time, waiting for a purer kick to bloom... &the future is still bleak, uncertain and beautiful..." -GSYBE

  6. #6
    Join Date
    Jul 2007
    Beans
    85
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Command line geek question

    I want to post a better version of my script. Unlike the previous one, this version won't be confused by special characters like spaces in file and directory names:

    Code:
    #!/bin/bash
    DCRAW="dcraw -w -c "
    
    
    while [ $# -ge 1 ]
    do
    
    targetdir="$1"
    
    for rawfile in "$targetdir"/*.[cC][rR][wW]
    
    do
        	
        OJPEG=$(echo "$rawfile"| perl -pe 's/\.crw$//i' | tr 'A-Z' 'a-z')'.jpeg'
        echo "${DCRAW} "$rawfile" | cjpeg > ${OJPEG}"
        ${DCRAW} -q 3 "$rawfile" | cjpeg -quality 100 > "${OJPEG}" || echo " *PROBLEM*"
        # transfer EXIF data from the original raw file
        exiftool -overwrite_original -TagsFromFile "$rawfile" "${OJPEG}" >/dev/null
        # preserve timestamps as much as possible
        # touch -r "$rawfile" "${OJPEG}"
        dcraw -z "${OJPEG}"
    
        # UNCOMMENT to delete raw files:
        # rm -f "$rawfile"
    
    done
        shift
        
    done

  7. #7
    Join Date
    Jul 2007
    Beans
    85
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Command line geek question

    Just learnt about the packages gimp-dcraw and gimp-ufraw. Don't know hw good the plugins are though.

    Edit:
    I also found RawTherapee and RawStudio.
    Last edited by sarang; January 2nd, 2009 at 05:42 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •