[Digikam-users] articuRe: Preview is "better" than RAW conversion?

Jeff Robinson jeffnik at anecho.mb.ca
Sun Aug 31 16:01:56 BST 2014


Hi Niels,

Here is the script that I cobbled together.  Let it be known that
there's absolutely no error checking or good coding practices contained
with-in!

I also mispoke when I said that this script used the preview... it looks
like PEF contains an embedded JPEG that is (almost) the same resolution
as the RAW file.  In a test the GIMP brings my RAW file in at 3040px x
2024px and the embedded JPEG at 3008px x 2000px.  Of course, my camera
is also a K100, and perhaps with a higher megapixel count the embedded
image is reduced.  Either way, here is the script and you'll be able to
compare the output.

Hopefully the word-wrap doesn't mangle the script too much.

#!/usr/bin/perl
# This script is used for extract JPEG previews from PEF files and then
copies over EXIF information
# When run with-out arguments the script will copy the JPEG previews and
EXIF information from
# all the PEF files in the current directory
# Otherwise a single or multiple file names can be list after the command
#
# JPEGs wil have the format of $filename.embedded.jpeg which matches the
output of ufraw-batch
#
# usage:
# arg_batch_and_tag
# or
# arg_batch_and_tag filename [filename2] [filename3]...
#
# Require software:
# ufraw-batch, which is part of ufraw: http://ufraw.sourceforge.net/
# exiftool, which is part of ExifTool:
http://www.sno.phy.queensu.ca/~phil/exiftool/
#
# (C)2014 Jeff Robinson
# This program is free software; you can redistribute it and/or modify
it under
# the terms of the GNU General Public License version 2, as published by the
# Free Software Foundation.

use Cwd;

my $totalarg = $#ARGV + 1;
my $curdir = cwd();

if ( $totalarg = 0 ) {
# No arguments were given so we'll run the script against all files in
the current directory

print "My current working directory is $curdir \n";

system("ufraw-batch --embedded-image *.pef");
system("ufraw-batch --embedded-image *.PEF");

opendir(DIR, $curdir);
@files = grep (/\.pef$/i,readdir(DIR));
closedir(DIR);

foreach $file (@files) {
	print "Copying EXIF information from $file...";
	$file =~ s/\.[^.]*$//;
	system("exiftool -overwrite_original_in_place -tagsFromFile $file.pef
$file.embedded.jpg");
	system("exiftool -overwrite_original_in_place -tagsFromFile $file.PEF
$file.embedded.jpg");
	print "completed.\n";
}

} else {
  # Use the supplied arguments as the files to process

  @files = grep (/\.pef$/i, at ARGV);

  foreach $file (@files) {
    $file =~ s/(.+)\.[^.]+$/$file/;
    $fileNoExtension = remove_extension($file);

    print("Extracting embedded image...\n");
    system("ufraw-batch --embedded-image \"$curdir/$file\"");
    print("Copying xmp file...\n");
    system("cp \"$curdir/$file.xmp\"
\"$curdir/$fileNoExtension.embedded.jpg.xmp\"");
    print("Writing EXIF information from original file to JPEG.\n");
    system("exiftool -overwrite_original_in_place -tagsFromFile
\"$file\" \"$fileNoExtension.embedded.jpg\"");
    print("Finished.\n\n");
  }

}

sub remove_extension {
    my $filename = shift @_;

    $filename =~ s/
                (.)             # matches any character
                \.              # the literal dot starting an extension
                [^.]+           # one or more NON-dots
                $               # end of the string
        /$1/x;

    return $filename;
}





On 08/31/2014 07:17 AM, Niels Ott wrote:
> Jeff,
> 
> I'd be very happy to have this script. And a digiKam integration would
> be so great.
> 
> After all, this would fit my purposes very well. I could give people a
> pile of JPEGs and let them know: This is the automatic thing in reduced
> resolution, if you want some of those in real good quality, just let me
> know.
> 
> So why not posting your script here, I don't see any problem with that.
> 
> I think this should make it into the extras menu, something like
> "Extract JPEG preview from RAW"
> 
> Best
> 
>    Niels
> 
> 
> Am 31.08.2014 um 14:08 schrieb Jeff Robinson:
>> Hi folks,
>>
>> If it is of any interest, I bashed together a small script that will
>> copy the preview JPEG (which I believe is full size and already
>> processed) out of Pentax RAW (PEF) files.
>>
>> The script works (using ufraw-batch) against either a whole directory or
>> will convert files based on names supplied, either single or multiple
>> files.
>>
>> Once the JPEG has been extracted the script then copies the XMP file
>> from the PEF to the JPEG and uses exiftool to write the EXIF information
>> from the PEF to the new JPEG as well.
>>
>> In my current work-flow I keep everything RAW and only convert a few of
>> the files to JPEG and process those by hand, but the ones I can't quite
>> ever get where I want, these scripts come in incredibly handy.
>>
>> I can post them if folks want... I'm not certain if that's against the
>> list policy.  The script is about 50 lines long.
>>
>> Now... if someone could figure out how to hook this script directly into
>> Digikam I'd be ecstatic!
>>
>> Jeff
>> _______________________________________________
>> Digikam-users mailing list
>> Digikam-users at kde.org
>> https://mail.kde.org/mailman/listinfo/digikam-users
>>
> 
> 



More information about the Digikam-users mailing list