Page 1 of 1

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

Posted: 2018-08-14T22:29:14-07:00
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?

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

Posted: 2018-08-15T08:23:04-07:00
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.

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

Posted: 2018-08-16T18:05:27-07:00
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.

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

Posted: 2018-08-16T18:40:32-07:00
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.

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

Posted: 2018-08-17T05:17:04-07:00
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.