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 »

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: 25562
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 »

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 »

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: 25562
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 »

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: 12159
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 »

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