Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a way to COPY EXIF information from one JPG to another in Linux?

1,331 views
Skip to first unread message

Tourgueniev

unread,
Oct 14, 2014, 7:54:18 PM10/14/14
to
Is there a way to COPY EXIF information from one JPG to another in Linux?

Something like:
$ copy pic1.exif.jpg pic2.exif.jpg

where the result is that the EXIF information is copied from picture 1 to
picture 2.

nospam

unread,
Oct 14, 2014, 8:05:40 PM10/14/14
to
In article <m1kd39$2h5$1...@dont-email.me>, Tourgueniev
get exiftool, which works on mac/windows/linux:

<http://www.sno.phy.queensu.ca/~phil/exiftool/>

Floyd L. Davidson

unread,
Oct 14, 2014, 8:41:21 PM10/14/14
to
The /exiftool/ program can be used to accomplish that,
but I wouldn't say it is "easy"! :-) You'd have to learn
a good bit about shell script programming to do it.

I've been using a script to do that for some years, so
it's fairly well tested, but it inserts
comments/copyright etc that are specific to my needs.
As written it also assumes Nikon generated files, and
for instance will read Exif data from NEF files but
refuses write to one.

I'll send you a copy of the script in email if you'd
like to have it. Send me an email telling me what
cameras you use, what name(s) might be in any copyright
notices in the original files and how you'd like
copyright notices to look when data is copied.

--
Floyd L. Davidson http://www.apaflo.com/
Ukpeagvik (Barrow, Alaska) fl...@apaflo.com
Message has been deleted

Tourgueniev

unread,
Oct 15, 2014, 2:08:39 AM10/15/14
to
On Tue, 14 Oct 2014 20:05:40 -0400, nospam wrote:

> get exiftool, which works on mac/windows/linux:

You gave me a great keyword to search for examples!

Searching on "exiftool", I immediately found this:
http://thomer.com/howtos/copy_exif.html

The very first test worked perfectly!
$ exiftool -TagsFromFile old.jpg new.jpg

This copied the EXIF data perfectly from old.jpg to new.jpg!

Of course, I should now be able to modify that EXIF data slightly, but
that's the next step to learn (which I had not originally asked about).

Tourgueniev

unread,
Oct 15, 2014, 2:31:04 AM10/15/14
to
On Tue, 14 Oct 2014 16:41:21 -0800, Floyd L. Davidson wrote:

> The /exiftool/ program can be used to accomplish that,
> but I wouldn't say it is "easy"!

Thanks for the idea of exiftool because a search for examples
found this web site which showed a perfect example:
http://thomer.com/howtos/copy_exif.html

The simplest copy from one file to another is:
exiftool -TagsFromFile old.jpg new.jpg

If we want to keep a tag out, we use double dashes:
exiftool -TagsFromFile old.jpg --Orientation new.jpg

I do realize this isn't at all sophisticated, in that some of the exif
data will be all wrong, such as

File Size : 100 kB
Exif Image Width : 480
Exif Image Height : 640
Image Size : 480x640

Is there an easy way to fix those 4 using either exiftool or exiv2?

Tourgueniev

unread,
Oct 15, 2014, 2:46:02 AM10/15/14
to
On Wed, 15 Oct 2014 01:23:33 +0000, Parko wrote:

> You could also try exiv2. Command line tool, so it may not suit you if
> you're all gooey like any other creative type. Check your distro's repos
> if its not installed by default.

I'm doing ok, so far, with the first suggestion, which was exiftool.

At the moment, it moved all the exif tags from one photo to the next,
but the problem now are the 4 problematic tags:
File Size : 100 kB
Exif Image Width : 480
Exif Image Height : 640
Image Size : 480x640

Googling for how to change exif data on linux, I found these examples:
http://dimitar.me/change-the-date-and-time-or-any-other-exif-image-meta-data-of-pictures-with-ubuntu/

This resets the dates to whatever you want them to be:
exiftool -AllDates='2014:10:10 15:35:33' -overwrite_original new.jpg

Testing that syntax with the 4 obvious exif tags above, I tried this:
$ ls -l new.jpg
-rw-rw-r-- 1 root root 67160 Oct 14 23:40 new.jpg

exiftool -File Size='67160' -overwrite_original new.jpg
But I apparently need to work on the syntax a little bit.

Floyd L. Davidson

unread,
Oct 15, 2014, 3:25:13 AM10/15/14
to
Tourgueniev <Tourg...@hotmail.com> wrote:
>The very first test worked perfectly!
>$ exiftool -TagsFromFile old.jpg new.jpg
>
>This copied the EXIF data perfectly from old.jpg to new.jpg!
>
>Of course, I should now be able to modify that EXIF data slightly, but
>that's the next step to learn (which I had not originally asked about).

A variation that is often very useful is,

$ exiftool -tagsfromfile old.jpg -tagsfromfile new.jpg new.jpg

That will retain all tags that exist in new.jpg, and add everything
from old.jpg that is not in new.jpg.

To change one specific tag,

# exiftool -tagname=new_value new.jpg

Quote text, so an example might be,

# exiftool -usercomment="Alpha Project" new.jpg

Try running exiftool with option '-s', and also '-s -s'. Notice
the difference in tag names and format, which can be useful in
making the output easier to parse.

Tourgueniev

unread,
Oct 15, 2014, 3:31:39 AM10/15/14
to
On Tue, 14 Oct 2014 23:25:13 -0800, Floyd L. Davidson wrote:

> A variation that is often very useful is,
>
> $ exiftool -tagsfromfile old.jpg -tagsfromfile new.jpg new.jpg
>
> That will retain all tags that exist in new.jpg, and add everything
> from old.jpg that is not in new.jpg.

Oooh. Thats a good one!
Very useful!

Tourgueniev

unread,
Oct 15, 2014, 3:48:03 AM10/15/14
to
On Tue, 14 Oct 2014 23:25:13 -0800, Floyd L. Davidson wrote:

> Try running exiftool with option '-s', and also '-s -s'.

That's interesting.
The first -s shortens the names by taking away spaces.
The second (seemingly redundant) removes more white space.

thanks.

Floyd L. Davidson

unread,
Oct 15, 2014, 5:24:11 AM10/15/14
to
Tourgueniev <Tourg...@hotmail.com> wrote:
>On Wed, 15 Oct 2014 01:23:33 +0000, Parko wrote:
>
>> You could also try exiv2. Command line tool, so it may not suit you if
>> you're all gooey like any other creative type. Check your distro's repos
>> if its not installed by default.
>
>I'm doing ok, so far, with the first suggestion, which was exiftool.
>
>At the moment, it moved all the exif tags from one photo to the next,
>but the problem now are the 4 problematic tags:
>File Size : 100 kB
>Exif Image Width : 480
>Exif Image Height : 640
>Image Size : 480x640

As you saw, in a previous post, easy to take care of... :-)

>Googling for how to change exif data on linux, I found these examples:
>http://dimitar.me/change-the-date-and-time-or-any-other-exif-image-meta-data-of-pictures-with-ubuntu/
>
>This resets the dates to whatever you want them to be:
>exiftool -AllDates='2014:10:10 15:35:33' -overwrite_original new.jpg
>
>Testing that syntax with the 4 obvious exif tags above, I tried this:
>$ ls -l new.jpg
>-rw-rw-r-- 1 root root 67160 Oct 14 23:40 new.jpg
>
>exiftool -File Size='67160' -overwrite_original new.jpg
>But I apparently need to work on the syntax a little bit.

If that would work, it would be, with no spaces in the
tag name.

exiftool -filesize='67160' new.jpg

Arguments are not case sensitive, but of course cannot
have whitespace. Use the -s option(s) to see
unambiguous tag names with no whitespace.

But the file size is not a tag (use the -G option to see
tag groups), it's just telling you what the actual
file size is, and you can't change that with exiftool.

The same happens with the image pixel dimensions, which
will always be determined empirically.

An example of a tougher problem is keeping the
Orientation tag correct. If you rotate an image in an
editor and write it out, the tag may still be for the
original image and will not be correct.

There may be other values that work, but I'm sure of these:

-orientation="rotate 90 cw"
-orientation="rotate 90"

-orientation="rotate 180"

-orientation="rotate 270 cw"
-orientation="rotate 270"

-orientation="normal"
-orientation="horizontal"
-orientation="horizontal (normal)"

Of course there is no way for a program to determine if
it is actually horizontal or a 180 degree rotation, and
the same with 90 and 270.

Since the image pixel dimensions are determined from the
file itself, not from a tag, it is always safe to use
those to calculate what the orientation flag should be.

Here's test script that shows some ways around a couple
pitfalls.

------ start of script ------
#/bin/bash

file="new.jpg"

height="$(exiftool -s -s -imageheight ${file} | cut -d' ' -f2)"
width="$( exiftool -s -s -imagewidth ${file} | cut -d ' ' -f2)"

echo "${width} W x ${height} H"

tagorient="horizontal" # default

#
# Send stderr to /dev/null to avoid seeing thr error if values are not digits
#
# ${result} will be:
# 0 landscape oriented image
# 1 portrait oriented image
# 2 invalid arguments, not digits
#
test "${height}" -gt "${width}" 2>/dev/null; result="${?}"

if [ "${result}" -eq 0 ] ; then
tagorient="rotate 90"
fi

if [ "${result}" -gt 1 ] ; then
echo "Either height (${height}) or (${width}) is invalid."
exit 1
fi

exiftool -orientation="${tagorient}" "${file}"

echo "orientation tag will be: $tagorient"

exiftool -orientation "${file}"
echo "Exit status of exiftool: ${?}"
exit 0
------ end of script ------

Tourgueniev

unread,
Oct 15, 2014, 9:02:37 AM10/15/14
to
On Wed, 15 Oct 2014 01:24:11 -0800, Floyd L. Davidson wrote:

> But the file size is not a tag (use the -G option to see
> tag groups), it's just telling you what the actual
> file size is, and you can't change that with exiftool.

I'm just slowly realizing that not everthing spit out by the
basic exiftool command (or viewed in an EXIF editor) is an exif tag.

Using the -G option, it looks like the groups (with an example) are:
[File] File Size : 65 kB
[EXIF] Exif Image Width : 392
[MakerNotes] HDR Image Type : Original Image
[XMP] XMP Toolkit : Image::ExifTool 9.46
[Composite] Image Size : 392x600

It's odd that the same thing (e.g., image size) is repeated over
and over again in the EXIF tags.

Usenet Account

unread,
Oct 15, 2014, 11:45:50 AM10/15/14
to
I am just curious as to why you want to copy EXIF?

--

Floyd L. Davidson

unread,
Oct 15, 2014, 4:49:30 PM10/15/14
to
Usenet Account <nos...@invalid.invalid> wrote:
>I am just curious as to why you want to copy EXIF?

Some editors don't copy all of the Exif (note that it is
not "EXIF") data. Also there is different data in RAW
files that is not in the JPEG.

But the main reason is to add or correct data in fields
such as comments, copyright, and so on. Another is to
fix lens identification tags... There are just a number
of little reasons.
0 new messages