Extracting into bash variables

Started by Alan Clifford, December 16, 2018, 10:23:32 AM

Previous topic - Next topic

Alan Clifford

I'm rewriting one of my old bash scripts. Is there a better way of extracting these data rather than three calls to exiftool?

ORIENTATION=`exiftool -orientation -n -s -s -s "${IMAGE}"`
WIDTH=`exiftool -imagewidth -n -s -s -s "${IMAGE}"`
HEIGHT=`exiftool -imageheight -n -s -s -s "${IMAGE}"`

Alan Clifford

I might be able to answer this myself.

cellini:test alan$ TESTING=`exiftool -s3 -n -orientation -imagewidth -imageheight ~/photographs/temp/x-s1_3655.jpg`


returns in the format

1 1024 683

I could put that straight into a bash array variable.  But need to look at, for instance, if orientation is missing.

Any other suggestions welcome though.

Alan Clifford

This might be it.  Need to test in script with an array.

cellini:test alan$ exiftool -m -s3 -n -p '0=$orientation 1=$imagewidth 2=$imageheight'  x-s1_3655.jpg

0= 1=1024 2=683

Phil Harvey

Maybe something like this?:

var=`exiftool -f -p 'export orientation="$orientation";export width=$imagewidth;export height=$imageheight' x-s1_3655.jpg`
$var
echo "orientation is $orientation"
...


-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 ($).

Alan Clifford

I'm getting the same sort of problem with as with trying to load an array - they text goes into the variable

orientation is: "-";export
width is:       1024;export
height is:      683

Alan Clifford

var=`exiftool -f -p 'export orientation="$orientation"  width=$imagewidth height=$imageheight' x-s1_3655.jpg`

looks like it works.


Alan Clifford

I'd progressed to:

declare -a stuffa
stuff=`exiftool -m -s3 -n -p '${orientation}x ${imagewidth} ${imageheight}'  x-s1_3655.jpg`
stuffa=(${stuff})

It had problems with missing orientation, hence the 'x', and I couldn't make it take defined array subscripts.

Your way is looking good.

I see, -f makes it work.

Alan Clifford


Alan Clifford

To change the - to a 0 would need MissingTagValue to be set.

Am I right in thinking I'd have to do this in a config file rather than using a command line option?

But I think I have a bash workaround for my purposes

orientation=$((${orientation}0/10))

or

orientation=${orientation#-}

StarGeek

Maybe you could use the -args option and then pipe that through sed to get the proper results?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Alan Clifford

i've settled on:

orientation=`exiftool -f -m -s3 -n -p '${orientation} ${imagewidth} ${imageheight}'  ${file}`
echo "${file} orientation:  ${orientation}"
a_orientation=(${orientation})  #array
i_orientation=${a_orientation[0]/-/0} #integer
i_width=${a_orientation[1]/-/0}
i_height=${a_orientation[2]/-/0}

Phil Harvey

Yes, you can use -api missingtagvalue=0 to change the missing tag value from "-" to "0".

- 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 ($).

Alan Clifford