Keep print size while converting bmp/png files

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
yampis
Posts: 3
Joined: 2017-10-15T23:22:49-07:00
Authentication code: 1151

Keep print size while converting bmp/png files

Post by yampis » 2017-10-15T23:42:56-07:00

Hello!

When I run program "convert in.bmp out.jpg" dpi and print sizes are modified.

For example

Image: in.bmp
Format: BMP3 (Microsoft Windows bitmap image (V3))
Class: DirectClass
Geometry: 2338x1653+0+0
Resolution: 78.34x78.34
Print size: 29.8443x21.1003
Units: PixelsPerCentimeter

Image: out.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 2338x1653+0+0
Resolution: 78x78
Print size: 29.9744x21.1923
Units: PixelsPerCentimeter

What should I do to keep exact geometry and print size?

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Keep print size while converting bmp/png files

Post by fmw42 » 2017-10-16T11:25:16-07:00

This is may just be a precision issue when using identify after conversion. The Resolution may simply be rounded or truncated to an integer when showing the value in identify. The IM developers will have to comment further.

yampis
Posts: 3
Joined: 2017-10-15T23:22:49-07:00
Authentication code: 1151

Re: Keep print size while converting bmp/png files

Post by yampis » 2017-10-17T04:51:48-07:00

It's not an issue in identify, because if I save bmp to jpg manually via XnView I have a difference in 4-th digit of print size.

Is there any workaround to fix print size via Imagemagick, for example:
1 - read print size from bpm
2 - convert bmp to jpg
3 - set print size to jpg without modifying pixels?

snibgo
Posts: 9385
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Keep print size while converting bmp/png files

Post by snibgo » 2017-10-17T07:57:36-07:00

BMP stores resolution as an integer number of pixels per metre, eg 7834 ppm. This is equivalent to pixels per centimetre with two decimal places, eg 78.34 ppcm.

I think JPEG stores resolution as integer number of pixels per centimetre or per inch. So 78.34 ppcm will be rounded to 78 ppcm.
snibgo's IM pages: im.snibgo.com

yampis
Posts: 3
Joined: 2017-10-15T23:22:49-07:00
Authentication code: 1151

Re: Keep print size while converting bmp/png files

Post by yampis » 2017-10-18T10:53:47-07:00

Is it possible to set custom print size to jpg without modifying pixels?

User avatar
fmw42
Posts: 22091
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Keep print size while converting bmp/png files

Post by fmw42 » 2017-10-18T12:05:48-07:00

yampis wrote:
2017-10-18T10:53:47-07:00
Is it possible to set custom print size to jpg without modifying pixels?
ImageMagick will always read the input and write the output even if just changing density.

You could use EXIFTOOL to reset the density without modifying the image pixels.

Post Reply