Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
SimonKravis
Posts: 4
Joined: 2013-03-25T16:44:12-07:00
Authentication code: 6789

Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Post by SimonKravis » 2018-08-14T22:29:14-07:00

I need to copy any existing EXIF, IPTC and XMP metadata from one JPEG file (sourceFile) to another (destinationFile) with a different size and a different image. I am using the code below, based on the posting https://stackoverflow.com/questions/343 ... adata?lq=1 which observes that when two images are composited, the metadata of the first one is retained.

Code: Select all

using (MagickImage sourceImage = new MagickImage(sourceFile))
                {
                    using (MagickImage destImage = new MagickImage(destinationFile))
                    {
                        int iDestWidth = destImage.Width;
                        int iDestHeight = destImage.Height;
                        sourceImage.Resize(iDestWidth, iDestHeight);                                             
                        sourceImage.Composite(destImage);
                    }
                    sourceImage.Write(destinationFile);
                }
However, sourceImage.Height does not change when destinationImage.Height has a larger value and the composited image does not have the destination Image in it. Metadata in the IPTC and XMP groups is also missing. What am I doing wrong?

User avatar
fmw42
Posts: 23656
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Post by fmw42 » 2018-08-15T08:23:04-07:00

Imagemagick does not write meta data. You have found one method that gets around that, but it also the limitations that you also have found.

I do not know if Magick.NET has any special code for that as I do not use it.

I would recommend you use EXIFTOOL to do your meta data copying.

SimonKravis
Posts: 4
Joined: 2013-03-25T16:44:12-07:00
Authentication code: 6789

Re: Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Post by SimonKravis » 2018-08-16T18:05:27-07:00

According to many examples, ImageMagick can write data. Exiftool can indeed copy all metadata using the command

Code: Select all

exiftool -TagsFromFile fromImage.jpg toImage.jpg
but it is very slow to start up on Windows.

User avatar
fmw42
Posts: 23656
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Post by fmw42 » 2018-08-16T18:40:32-07:00

Let me clarify my comments. Imagemagick will copy exif data from an input to an output. I know of no universal way that allow imagemagick to transfer appropriate exif data from one image to some other arbitrary image. I will defer to the developers for a definitive response.

snibgo
Posts: 10550
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Copy EXIF, IPTC and XMP metadata from one JPEGfile to another

Post by snibgo » 2018-08-17T05:17:04-07:00

exiftool starts slowly on Windows on its first time because it creates nearly 1000 files in %TEMP%. Thereafter, it is much faster.

You say you want to copy metadata from sourceFile to destinationFile. But the code in the OP does the opposite, changing sourceFile from destinationFile.
snibgo's IM pages: im.snibgo.com

Post Reply