How to get an alpha channel from a png

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
wojciech.debowski

How to get an alpha channel from a png

Post by wojciech.debowski »

Hi,

I want to create a mask image. I want to use an alpha channel as a mask but I don't know how to get an alpha channel from a png image in perl script. I am new in perl and ImageMagick, Can somebody help?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to get an alpha channel from a png

Post by anthony »

Just extract the alpha channel. look for separate in the perlmagick docs
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
wojciech.debowski

Re: How to get an alpha channel from a png

Post by wojciech.debowski »

Separate works, thanks, but I still have a problem when converting this mask to bmp,
I have a png image and I want to have a 8bit grayscale bmp mask and 24bit bmp image, I try this to create the mask
convert image.png -channel matte -negate -separate mask.bmp
output mask.bmp has 1-bit alpha channel, later when I build from this bmp symbian mbm file I get horrible effect. How to remove this 1-bit alpha channel from output bmp image??? I tried to add -type TrueColor
convert image.png -channel matte -negate -separate -type TrueColor mask.bmp
but it didn't change anything, can someone help, it is very important for me now
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to get an alpha channel from a png

Post by anthony »

To remove the alpha from the image use Evaluate to set the alpha mask to opaque. or just turn off the 'matte' channel.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
wojciech.debowski

Re: How to get an alpha channel from a png

Post by wojciech.debowski »

I added +matte option to remove alpha channel from output image:
convert image.png -channel matte -negate -separate +matte -depth 8 mask.bmp
I still get mask.bmp with 1bit alpha channel, its type is Gra yScaleMatte, why?
I also tried to add -type Grayscale to this command but I always get GrayScaleMatte with this 1bit alpha channel.
Can You write me how to remove this alpha channel with -evaluate option?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to get an alpha channel from a png

Post by anthony »

Sounds to me like the BMP code always adds it. have you tried one of the other BMP formats.
List all formats with

Code: Select all

convert -list format
In my list I see BMP2 and BMP3 as alturnatives.

Code: Select all

convert image.png -channel matte -negate -separate +matte -depth 8 bmp3:image.bmp
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
wojciech.debowski

Re: How to get an alpha channel from a png

Post by wojciech.debowski »

This works! Hurra hurra! alpha channel has been removed from mask.bmp,
great great great thanks!
Post Reply