G'MIC request: keep exif info

Salut David,

This weekend I batch-processed a series of photos with G’MIC. The resulting pictures lack any exif info. This means for example that photos aren’t automatic rotated anymore based on exif info, so I had to do that by hand in my Flickr account. Other info that might interest photographers like lens used, diaphragm or shutter speed, or maker notes, are gone as well. Click on the photo below, then Show exif, to see what I mean.

We spoke before about this and you said “G’MIC doesn’t care/use exif”, so my question is, is it possible to add a switch like -keepexif that, eh… keeps exif info intact?

Thanks for reading.

Cordialement, Paul.

Hello Paul,
For keeping Exif info, I’d suggest to use exiftool instead. There are absolutely no structures in the G’MIC libraries to deal with that. I understand this can be a bit annoying for people who want to process images with G’MIC of course, but I think I can’t do much for them at the moment.

Thanks David,

Phil Harvey (the author of exiftool) gave the solution himself:
-wm cg -tagsfromfile “org.jpg” -all:all “gmic.processed.jpg”.

Problem solved!

1 Like

I’ll expand on that, with some info from experience and from the manual.

  • Port metadata from the source photo into a final image (the file formats can differ):

exiftool -writeMode cg -TagsFromFile “source.raw” -all:all “final.jpg”


* You can also save metadata from an image into an XMP file, which you could manually edit in a text editor, and then move it from the XMP file into an image:

exiftool -TagsFromFile source.raw meta.xmp
exiftool -TagsFromFile meta.xmp final.jpg

Or you can use the MIE format instead of XMP, [for reasons](http://search.cpan.org/~exiftool/Image-ExifTool-10.20/lib/Image/ExifTool/MIE.pm#WHAT_IS_MIE?). Just replace "xmp" with "mie" in the two lines above.

* The examples above operate on a single file at a time. This one processes a whole folder, you can use it if the names of your final images match the names of the source images. It recursively rewrites all "JPG" images in "dir" with information copied from the corresponding "CR2" images in the same directories:

exiftool -TagsFromFile %d%f.CR2 -r -ext JPG dir


* Same example as above but different folder structure. If the files you want to get metadata from (e.g. raw files of various formats) are in "`source/*`" and the files you want to write the metadata to are in "`destination/*.jpg`"

exiftool -TagsFromFile @ -srcfile destination/%f.jpg source

It would automatically copy metadata:

source/amsterdam.pef → destination/amsterdam.jpg
source/barcelona.raf → destination/barcelona.jpg
source/chicago.dng → destination/chicago.jpg


* Save metadata in XMP format for each image in "dir":

exiftool -o %d%f.xmp dir

For gmic/exiftool integration I do:

One file:
$ gmic image.jpg -my_gmic_function -o processed.jpg; exiftool -wm cg
-tagsfromfile “image.jpg” -all:all “processed.jpg”; rm *_original

Batch:
for i in *.jpg; do echo $i; gmic $i -my_gmic_function(s) -o
gmic.processed.$i; exiftool -wm cg -tagsfromfile “$i”
-all:all “gmic.processed.$i”; rm *_original;done

Quote your variables!

for i in *.jpg; do
  printf '\n%s\n' "$i"
  gmic "$i" -my_gmic_functions -o "gmic.processed.$i"
  exiftool -delete_original -wm cg -tagsfromfile "$i" -all:all "gmic.processed.$i"
done
1 Like

You haven’t seen any gmic terminal output I suppose?

Correct, though that’s irrelevant. Always quote your variables.

I hope you don’t mind that I do what I want. Thanks for your attention.

Oh, can I chime in too?

If the image has been rotated, and you transfer the EXIF data using something like

exiftool -TagsFromFile src.raw out.jpg

Then the orientation will be wrong (and you’ll see this in Flickr for instance).

To fix this, you can explicitly set the Orientation flag after you’ve transferred the other exif data:

exiftool -Orientation=Normal out.jpg

If the embedded thumbnail doesn’t match your actual image and you want to remove it (or just want to save the few extra bits:

exiftool -ifd1:all= out.jpg

will strip the thumbnail info out of your EXIF data.

Goes without saying that I don’t mind at all - your files, your loss - but this is public, and people are learning from what we type. What happens when a file contains a space, a quotation mark, a dollar sign, or a bunch of other possibilities in the filename? Your command will fail. And what happens if the G’MIC command which follows the space begins with anything that happens to be a Linux command? Best case scenario, copying metadata fails. Worst case scenario, files are moved, overwritten or deleted. And all that needs to be done to prevent this, is to quote your variables.

  1. https://github.com/MrMEEE/bumblebee-Old-and-abbandoned/commit/a047be85247755cdbe0acce6f1dafc8beb84f2ac#diff-3fbb47e318cd8802bd325e7da9aaabe8R351
  2. Moved ~/.local/share/steam. Ran steam. It deleted everything on system owned by user. · Issue #3671 · ValveSoftware/steam-for-linux · GitHub
    etc.
2 Likes