Writing image file output to standard output rather than a file

Started by drb333, February 09, 2011, 09:26:37 AM

Previous topic - Next topic

drb333

Hi,

I am writing a shell script to compare two JPG files, both stripped of all EXIF information. The reason I want to do this is because I have lots of JPG files that are not exact binary duplicates, but they only differ in EXIF information added by iPhoto during import.

I know one way to do this:

exiftool -q -all= -o a.jpg originala.jpg
exiftool -q -all= -o b.jpg originalb.jpg
diff a.jpg b.jpg


This works fine, but I am hoping there is a way to do this without generating the intermediate files a.jpg and b.jpg.

I tried this:

diff <(exiftool -all= -o &1 $1) <(exiftool -all= -o &1 $2)

where $1 and $2 are the original file names passed into the shell script via the command line. The hope is that exiftool would write EXIF-less JPG to standard output where it is redirected to the diff command. I thought this would be clever, but it doesn't work. Instead, I get the error "Expected output file or directory name for -o option".

I've searched the forums for other approaches but I've come up empty. If anyone has any ideas, I would be happy to try them.

Thanks,
Rick

Phil Harvey

Hi Rick,

Use -o - to send the exiftool output file to stdout.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

drb333

Hi Phil,

This works! I apologize if this is documented somewhere and I missed it. Thanks for your help.

Thanks,
Rick

Phil Harvey

Hi Rick,

I don't think you missed anything.  I will add this to the documentation.  This isn't an exiftool-specific feature (Perl implicitly opens stdout when you open "-" for writing), but is worth noting in the documentation anyway.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

drb333

In case anyone is interested, here is my script. I'm sure more experienced shell programmers will immediately see ways to make this better, but I'm just using this for maintaining my personal photo library.

Thanks,
Rick

-------

#!/bin/bash

if diff -s $1 $2
then
        # files are the same
        # nothing to do
        # echo Done.
        exit 0
else
        # files differ

        # check to see if the difference is something other than the exif
        if diff <(exiftool -all= -o - $1) <(exiftool -all= -o - $2)
        then
                echo The nonEXIF parts of these files are identical.
        else
                echo The nonEXIF parts of these files differ.
        fi

        # check to see what differs in the exif
        if diff <(exiftool -a -u $1) <(exiftool -a -u $2) > /dev/null
        then
                echo The EXIF parts of these files are identical.
        else
                echo -n The EXIF parts of these files differ. Show differences? [y/N]:
                read answer
                if [ "$answer" = y -o "$answer" = Y ]
                then
                        diff <(exiftool -a -u $1) <(exiftool -a -u $2)
                fi
        fi
fi