using -define png:color-type=2 add grey row to bottom

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
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

using -define png:color-type=2 add grey row to bottom

Post by jmaeding »

I have a bunch of 16x16 pixel button images, whose "background" color was 192,192,192.
I need to replace that with transparency, and save as RGB png.
The replace is easy using:
(step1)
magick mogrify -fuzz 0%% -transparent "rgb(192,192,192)" "C:\CAD_Support\Menu Images\*.png"
But then many images get saved with indexed palette, not 24 bit rgb.
So I convert to RGB with:
(step 2)
magick mogrify -define png:color-type=2 "C:\CAD_Support\Menu Images\*.png"

and it runs, but on many images I get a grey (194,194,194) row along the bottom.
I can't get rid of that row, as step 1 converts it back to indexed palette.

I tried many other things, but none helped, only did bad things like removing transparency.
Am I dealing with a canvas edge issue?
thanks
James Maeding
Civil Engineer / Programmer
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: using -define png:color-type=2 add grey row to bottom

Post by fmw42 »

What is your ImageMagick version 7.x.x.x and platform (presumed Windows)? Please always provide that information. Can you post one example input image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: using -define png:color-type=2 add grey row to bottom

Post by fmw42 »

I think if you want to keep transparency you need to use color-type=6. See https://www.imagemagick.org/Usage/formats/#png_write

Try

Code: Select all

magick mogrify -define png:color-type=6 -fuzz 0%% -transparent "rgb(192,192,192)" *.png
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

Re: using -define png:color-type=2 add grey row to bottom

Post by jmaeding »

sorry, on windows 10, IM version 7.0.5-Q8
I tried the code above, and it does replace the color with trans, but the final png is Indexed Color.
James Maeding
Civil Engineer / Programmer
jmaeding
Posts: 54
Joined: 2006-05-03T09:48:26-07:00

Re: using -define png:color-type=2 add grey row to bottom

Post by jmaeding »

wait, it did work. I ran an old script on accident.
Dang, Fred gets it in one! very nice.
James Maeding
Civil Engineer / Programmer
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: using -define png:color-type=2 add grey row to bottom

Post by fmw42 »

Yes, it should have worked. I tested it on the logo: image making white transparent and the result was 32-bit color. Glad if worked for you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: using -define png:color-type=2 add grey row to bottom

Post by fmw42 »

jmaeding wrote: 2018-07-30T16:19:58-07:00 sorry, on windows 10, IM version 7.0.5-Q8
I tried the code above, and it does replace the color with trans, but the final png is Indexed Color.
An easy way not to forget, especially for users who do not upgrade often, is to put the version and platform information in your footer. But then you have to be sure to update it when you upgrade.

You might consider an upgrade now. I am not sure what 7.0.5.x you are using, but we are now at 7.0.8.8. So as much as 30 or more versions old.
Post Reply