converting png to grayscale changes resolution and size

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
davidjkelly
Posts: 4
Joined: 2012-09-17T07:54:49-07:00
Authentication code: 67789

converting png to grayscale changes resolution and size

Post by davidjkelly »

We are using this command to convert images to grayscale:

convert source.png -channel RGBA -strip -colorspace gray output.png

For some PNGs, the resolution and x,y dimensions change after this conversion, although the number of pixels remains the same. For instance, the following sample image begins at 319.964dpi, 2.25in X 4in and ends at 72dpi, 10in X 17.778in.

Here is the sample input image: https://dl.dropbox.com/u/33092204/initialScreenShot.png

...and output image: https://dl.dropbox.com/u/33092204/initi ... hot_BW.png

Is there a way to keep the original resolution and size? In reading what I can about this, it seems like it should be accepting the original size of the PNG and not changing it. I have tried using -density to pass it the original dpi, but it still changes the output to the default 72dpi.

I am using ImageMagick 6.7.9-3 2012-08-27 Q16 on a Windows Vista 64bit machine.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: converting png to grayscale changes resolution and size

Post by glennrp »

The "-strip" option removes the resolution data (PNG pHYs chunk), so the image falls back on the default value, 72dpi. So to keep the original resolution, omit "-strip".

Incidentally, I was wondering what software you used to create the original screenshot.
davidjkelly
Posts: 4
Joined: 2012-09-17T07:54:49-07:00
Authentication code: 67789

Re: converting png to grayscale changes resolution and size

Post by davidjkelly »

Much thanks, that took care of it.

We originally added the -strip option to remove the color profile. Is there a way to remove the color profile without the -strip option? My understanding (I could be wrong) is that even though the file is grayscale, it could still have a color profile.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: converting png to grayscale changes resolution and size

Post by glennrp »

davidjkelly wrote:We originally added the -strip option to remove the color profile. Is there a way to remove the color profile without the -strip option? My understanding (I could be wrong) is that even though the file is grayscale, it could still have a color profile.
Yes but it's a little more complicated if you want to strip some chunks but not all of them. You can use +profile or -define png:exclude-chunk=iCCP to strip just the profile (although the latter might just cause the profile to be uuencoded into a text chunk). It's probably OK to have a color profile in a grayscale image provided the color transfer curves are all three the same, but strictly speaking a grayscale image should only have a grayscale profile, and the PNG specification requires that.
davidjkelly
Posts: 4
Joined: 2012-09-17T07:54:49-07:00
Authentication code: 67789

Re: converting png to grayscale changes resolution and size

Post by davidjkelly »

Thanks again, that helps considerably.

To answer your earlier question about the screen capture (missed it earlier) -- I don't know, but I'll try to find out from the author who provided the file.
davidjkelly
Posts: 4
Joined: 2012-09-17T07:54:49-07:00
Authentication code: 67789

Re: converting png to grayscale changes resolution and size

Post by davidjkelly »

Here's the author's capture method:

"For the non-device screen captures, including the emulator screenshots, I just pressed alt-printscreen and pasted it directly into Paint.NET. My monitor resolution is 1920x1080. For the device screen captures, I used Android DDMS to do the screen capture directly off of the device; I believe the device res for my device is 1280x720. It was very large on my screen before I increased the resolution to make it smaller."

Large screen, high resolution, use as much real estate as possible. They came out large and crisp.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: converting png to grayscale changes resolution and size

Post by glennrp »

The reason I asked was that I wondered about the source of the embedded ICC profile. Apparently eiher the Android screen capture software or Paint.NET supplied it. Thanks.
Post Reply