Avoiding loss of EXIF when using convert -density

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
JDoe

Avoiding loss of EXIF when using convert -density

Post by JDoe »

Hi at all,

I am working on a small enhancement of a workflow-system. Users deliver some photos to the system and these photos have typically a resolution of 72 x 72 DPI and containing EXIF metainformation.

As those photos are used for printing in magazines the idea is to have a hot folder on the system and change the resolution. At the moment I have no idea how I should deal with the hot folder thing, but I will do this later as I decided first to see if IM will help me for the resolution change.

So what I did so far is a command-line test:

Code: Select all

convert c:\sample\in.jpg -density 300x300 c:\sample\out.jpg
(Just working on WIndows 7, but it must be implemented on a linux-box - Suse Linux Enterprise 10 SP2)
OK, this seems to work fine but I have two questions here:

1.)
With this operation I loose the integrated EXIF information of the photo.
What can I do to avoid the loss of the EXIF data as we need them later in the workflow for some decisions?



2.)
I realized that I have a gap in the graphics size.
in.jpeg = 3.001.842 Bytes
out.jpeg = 3.545.200 Bytes

So the output-file is larger than the input-file. But if I understand the IM-manual right '-density' should not affect the graphics content.
So what happens here?
Is it a re-compression of the JPEG?
How can I avoid this?


I am absolutely new to IM and I am also not very familiar with the details of computergraphics but I hope I am not to wrong :)


Best regards and thanks for helping me!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Avoiding loss of EXIF when using convert -density

Post by fmw42 »

IM will decompress and recompress your jpg. Nothing I know of to prevent that. (Someone correct me if I am wrong).

You can control the recompression by adding -quality XX

You may need another tool that is capable of changing density without reprocessing the image. Photoshop for example will not reprocess the image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Avoiding loss of EXIF when using convert -density

Post by snibgo »

If all you want to do is change metadata, "exiftool" may be a better choice. ImageMagic is primarily about converting and changing images. As you suspect, IM is decompressing the image, then compressing it again (at the default setting, which I think is 85).

IM would be great at creating thumbnails and so on, at different sizes, perhaps with captions on the image, to a common colour profile.
snibgo's IM pages: im.snibgo.com
JDoe

SOLVED: Avoiding loss of EXIF when using convert -density

Post by JDoe »

I did not mentioned that the workflow is automated up to a certain level so using an application like Photoshop is not possible - in fact that is how we do it at the moment but we want to speed up the whole process and therefore we try to automate all the steps that always the same.

How ever you helped me very much - as I know now IM is a multifunctional tool but it does not cover my needings. So I will try to use 'exiftool'.

Thanks a lot! *thumbsup*
billbell52

Re: Avoiding loss of EXIF when using convert -density

Post by billbell52 »

Maybe I am not understanding this but I use the -resample command to change the dpi on .jpg. I don't think it is recompressing the image. Will that work?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Avoiding loss of EXIF when using convert -density

Post by fmw42 »

Resample will reprocess the image also (since it changes the width and height), as I understand it. Furthermore, JPGs have to be decompressed and recompressed.

From the options page:

"Resample image to specified horizontal and vertical resolution.
Resize the image so that its rendered size remains the same as the original at the specified target resolution. For example, if a 300 DPI image renders at 3 inches by 2 inches on a 300 DPI device, when the image has been resampled to 72 DPI, it will render at 3 inches by 2 inches on a 72 DPI device. Note that only a small number of image formats (e.g. JPEG, PNG, and TIFF) are capable of storing the image resolution. For formats which do not support an image resolution, the original resolution of the image must be specified via -density on the command line prior to specifying the resample resolution.

Note that Photoshop stores and obtains image resolution from a proprietary embedded profile. If this profile exists in the image, then Photoshop will continue to treat the image using its former resolution, ignoring the image resolution specified in the standard file header."
Post Reply