Retaining EXIF after composite operation

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
gaspako

Retaining EXIF after composite operation

Post by gaspako »

I use this (taken from IM resize usage page)

Code: Select all

 convert src.jpg -resize 720x480 -size 720x480 xc:white +swap -gravity center -composite out.jpg
to get this:
Image
(resized portrait source into the landscape output where unused area is filled with white)

The problem I have with this procedure is that the output jpeg does not retain the EXIF info from the source image.
Is there a way to tell IM to transfer EXIF data from the source to the output image?
Or, is there another way to achieve the above resize effect while keeping the EXIF data in the output?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Retaining EXIF after composite operation

Post by fmw42 »

gaspako wrote:I use this (taken from IM resize usage page)

Code: Select all

 convert src.jpg -resize 720x480 -size 720x480 xc:white +swap -gravity center -composite out.jpg
to get this:
Image
(resized portrait source into the landscape output where unused area is filled with white)

The problem I have with this procedure is that the output jpeg does not retain the EXIF info from the source image.
Is there a way to tell IM to transfer EXIF data from the source to the output image?
Or, is there another way to achieve the above resize effect while keeping the EXIF data in the output?
I know nothing about transfer of EXIF data, but doubt any system will transfer that info after processing the image to make it smaller and insert it into another image background, etc, because the result is no longer the same image. What if I were to mosaic 100 images together? What EXIF data would you expect in the result? There may be tools that will let you copy the EXIF data from one image and then insert it into another image. You may want to do a Google search. I will stand corrected, if one of the IM teams says otherwise.

But as for your processing, an easier way is to resize the image and then pad it out with background color:

convert src.jpg -resize 720x480 -background white -gravity center -extent 720x480 out.jpg
gaspako

Re: Retaining EXIF after composite operation

Post by gaspako »

Thanks for your suggestion on the resize.
It works the way I need and the output image keeps all the EXIF data - except for the size, of course. :D
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Retaining EXIF after composite operation

Post by anthony »

The -extent will solve the problem.

However as a FYI this is what is actually going on.

When IM Alpha Composes two images. the meta-data for the image (the EXIF info, comments, labels, and other profiles, are taken from the destination image. that is the destination image is modified by the given source or overlay image.

In the above command the destination image (thanks to the +swap) is a blank white canvas! As such it has very little meta-data. There is little you can do about this as the final image size (what you are wanting from the compose) also comes from the destination image!!!

On the other hand -extent modifies the original image, and as such the meta-data of the original image is preserved, including the EXIF information.

The '-border -crop' method which is also on the IM Examples thumbnails page, will also preserve the meta-data and can be used for IM versions which are too old for the faster -extent method.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
gaspako

Re: Retaining EXIF after composite operation

Post by gaspako »

Yes, -extent did the trick, thank you.
Post Reply