Is it possible to replace the image portion of a JPG but keep the embedded metadata? Alternatively, is there a way to reliably copy all metadata from one JPG image to anothe
I think that ImageMagick can help you.
I saw that ImageMagick example where you can see how to extract all metadata from a jpg file.
Now if you have the metadata of the original file, you can create a new file with that metadata. I found a example of how to add metadata with ImageMagick
I hope this can help you
You can do this with ImageMagick - here is one way.
Load the original image with the metadata you want to preserve, then load the "fake" image and composite that over the top of the original and save, and ImageMagick will preserve the original image's metadata. Let's do an example.
Here is an original image, let's check the metadata with jhead
jhead original.jpg
File name : original.jpg
File size : 2080473 bytes
File date : 2015:12:18 09:05:53
Camera make : Apple
Camera model : iPhone 4S
Date/Time : 2014:12:25 15:02:27
Resolution : 3264 x 2448
Flash used : No
Focal length : 4.3mm (35mm equivalent: 35mm)
Exposure time: 0.0083 s (1/120)
Aperture : f/2.4
ISO equiv. : 50
Whitebalance : Auto
Metering Mode: pattern
Exposure : program (auto)
GPS Latitude : N 54d 26m 14.84s
GPS Longitude: W 3d 5m 49.91s
GPS Altitude : 226.00m
JPEG Quality : 95
Now, we run the process I suggested, compositing a grey (fake) image of the same size over the top:
convert original.jpg fake.jpg -composite new.jpg
and we get this:
And if we check the metadata of the new image:
jhead new.jpg
File name : new.jpg
File size : 43408 bytes
File date : 2015:12:18 09:08:30
Camera make : Apple
Camera model : iPhone 4S
Date/Time : 2014:12:25 15:02:27
Resolution : 3264 x 2448
Color/bw : Black and white
Flash used : No
Focal length : 4.3mm (35mm equivalent: 35mm)
Exposure time: 0.0083 s (1/120)
Aperture : f/2.4
ISO equiv. : 50
Whitebalance : Auto
Metering Mode: pattern
Exposure : program (auto)
GPS Latitude : N 54d 26m 14.84s
GPS Longitude: W 3d 5m 49.91s
GPS Altitude : 226.00m
JPEG Quality : 96
... and suddenly the grey rectangle I just made two minutes ago on my Mac was taken on Christmas Day last year at exactly the same spot as the original in the Lake District :-)
If your fake image and original differ in size, you can do this to force them to a common size before compositing (so that the fake completely covers the original) like this:
convert original.jpg fake.jpg -resize 3264x2446! -composite new.jpg