exiv2 & find
Added by Günter Haus over 11 years ago
Hi,
using bash under Linux I need to embed a metatag to image files which contain barcodes which are parsed by the zbarimg tool, i usually do this with following command:
exiv2 -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw image.tif`" image.tif
which works fine for single files. zbarimg is returning the barcode content which is then emeded into the file.
However I need to do this recursivly for whole directories and subdiretories structures.
I use to handle such jobs with the find -exec command, which in this case would looks like this:
find . -name '*.tif' -exec sh -c 'exiv2 -M \"set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw {}`\" {}' \;
Unfortunately this doesn't work because exiv2 is complaining wrong arguments to option -M.
Trying a very similar command by substituting "exiv2" by "echo" to debug the line this way:
find . -name '*.tif' -exec sh -c 'echo \"set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw {}`\" {}' \;
shows, that the syntax is exactly like exiv2 usually expects, but where does then the error come from?
Someone please could me a hint what's going wrongß
THX in advance
Replies (6)
RE: exiv2 & find - Added by Andreas Huggel over 11 years ago
Hi Günter,
You may have to look for a more generic UNIX list to get an answer for that question. I don't think the observed (mis)behaviour has anything to do with exiv2.
As a workaround you could try with an explicit loop instead, something like
for i in `find . -name '*.tif'` ; do exiv2 -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw $i`" $i ; done
Andreas
RE: exiv2 & find - Added by Robin Mills over 11 years ago
Hi Günter
I agree with Andreas that this is a UNIX shell puzzle and unlikely to be anything wrong with exiv2. The command echo isn't the best way to diagnose this stuff. I have a tiny utility "args" (for which I've posted the code below) which I find very useful for debugging this kind of issue.
You'll notice that
$ echo how now brown cow
and
$ echo "how now brown cow"
produce identical output in the terminal, however args is much more illuminating:
529 /Users/rmills/clanmills $ args how now brown cow
0 : args
1 : how
2 : now
3 : brown
4 : cow
530 /Users/rmills/clanmills $ args "how now brown cow"
0 : args
1 : how now brown cow
531 /Users/rmills/clanmills $
I'm also a little surprised that you use -exec sh -c bla bla in your find command. I always simply use -exec exiv2 bla dee bla etc... However I don't think that's the issue here as my suspicion is that your `....` stuff is broken into many little arguments.
// args.cpp #include <stdio.h> #include <stdlib.h> #include <string.h> char print(unsigned char c) { return ( 32 <= c && c <= 127 ) ? c : '?' ; } int main(int argc, char* argv[]) { int i = 0 ; while ( i < argc ) { printf("%-2d: %s\n",i,argv[i]) ; i++ ; } return 0 ; }
[solved] RE: exiv2 & find - Added by Günter Haus over 11 years ago
Many thanks Robin for your input and this very helpful little tool. I used it for some testing and found out that my above stated one-liner is doing well for all images containg a qrcode. But the zbarimg command part is not providing a result on images not conatining a qrcode. In those cases the final parameter for exiv2 remains NULL and exiv2 is complaining this. It seems like exiv2 is unable to set the content of a tag to "" (NULL) or " " (SPACE). The error I mentioned in my first post was then thrown just for such images.
I would have never found this without your support.
Just for the records (and if someone should evre stumble about a similar prob) I have updated my one-liner to make shure that it works with all images by adding one additional character like this:
find . -name '*.tif' -exec sh -c 'args -M "set Exif.Image.DocumentName `zbarimg -q -Sdisable -Sqrcode.enable --raw {} & echo -n "_"`" {}' \;
Although not completely perfect, this is a solution I can live with, but will continue to search if I can convince exiv2 to accept a one-space-character as a tag content.
again
THX and kind regards
RE: [solved] RE: exiv2 & find - Added by Andreas Huggel over 11 years ago
Although not completely perfect, this is a solution I can live with, but will continue to search if I can convince exiv2 to accept a one-space-character as a tag content.
$ ./exiv2 -M'set Exif.Image.DocumentName ""' exiv2-empty.jpg $ ./exiv2 -pa exiv2-empty.jpg Exif.Image.DocumentName Ascii 0
RE: exiv2 & find - Added by Günter Haus over 11 years ago
And the winner is:
find . -name '*.tif' -exec sh -c 'exiv2 -M "set Exif.Image.DocumentName \"`zbarimg -q -Sdisable -Sqrcode.enable --raw {}`\"" {}' \;
This one is exactly doing what I was looking for!
I do thank you both Robin & Andreas
RE: exiv2 & find - Added by evan pan about 6 years ago
Hi,
Here are some tutorials about barcode reading processing I found by Google:
http://www.pqscan.com/read-barcode/barcode-csharp.html
http://www.pqscan.com/read-barcode/
I hope it helps. Good luck.
Best regards,
Pan