transparent background - How! (solved!)

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
Albireo
Posts: 68
Joined: 2010-01-12T03:32:23-07:00
Authentication code: 8675309

transparent background - How! (solved!)

Post by Albireo »

Hello!
My wish is to place an image on a transparent background.
(Background size 400x400 - image size maybe 300x400 or 400x300)

I have no problem to get an background, red, yellow or blue, but transparent......
The "transparent" background becomes usually black.

Sometimes I have succeeded with a transparent background,
but then I changed any parameter(size,path,images...), the background was black again.
If the change was restored the background remained black....

Have tested a number of variants of commands.
(here, an example (In Windows - one row):

Code: Select all

convert -define jpeg:size=400x400 hatching_orig.jpg -resize "400x400>" -background transparent -gravity center -extent 400x400 pad_extent.jpg
//Jan
Last edited by Albireo on 2010-01-19T09:04:44-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: transparent background - How!

Post by Bonzo »

jpg does not support transparency - use png
Albireo
Posts: 68
Joined: 2010-01-12T03:32:23-07:00
Authentication code: 8675309

Re: transparent background - How!

Post by Albireo »

Thanks very much, I had forgot it :-)
imagecorpis

Re: transparent background - How! (solved!)

Post by imagecorpis »

Hello,

I'm gonna use this thread since I have also a transparency related question.

I'm converting PNG files to 24-bit bitmaps, which as far as I know also don't support an alpha channel.
I would know to know if there is any way to map the alpha channel to a BMP image.

Let me explain better, I have a file.pgn texture with a transparent background. I want to convert this
to file.bmp (easy), and then have a second file_alpha.bmp file with the transparent background mapped as black
and white pixels. Is there a convert parameter to do that?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: transparent background - How! (solved!)

Post by fmw42 »

If I understand you correclty -- if your png file has transparency and you want to get a bmp file that is black/white representing only the transparency then try

convert image.png -alpha extract image_alpha.bmp

see http://www.imagemagick.org/Usage/basics/#alpha_extract


also see http://www.imagemagick.org/Usage/formats/#bmp as that says you can have 32-bit BMP (24-bit color and 8-bit transparency)

However, I cannot seem to get the transparency into the bmp by

convert logo2t.png -channel rgba -alpha on -depth 8 logo2t.bmp
imagecorpis

Re: transparent background - How! (solved!)

Post by imagecorpis »

That's exactly what I'm looking for, however using convert file.png -alpha extract file_alpha.png returns this:

convert: UnrecognizedAlphaChannelType 'extract'

I've tried both the 6.3.9 Windows static version as well as a later 6.5.9 Windows Static compiled from source.

I'm also interested in converting .PNGs with alpha to the 32-bit BMP with alpha format, that would be even better for my purposes.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: transparent background - How! (solved!)

Post by fmw42 »

imagecorpis wrote:That's exactly what I'm looking for, however using convert file.png -alpha extract file_alpha.png returns this:

convert: UnrecognizedAlphaChannelType 'extract'

I've tried both the 6.3.9 Windows static version as well as a later 6.5.9 Windows Static compiled from source.

I'm also interested in converting .PNGs with alpha to the 32-bit BMP with alpha format, that would be even better for my purposes.
-alpha extract is relatively new, but should be there fine for 6.5.9 (as that is what I use and it works). 6.3.9 is probably too old.

you can also get the alpha channel in older releases by

convert image.png -channel A -negate -separate image_alpha.png


about 32-bit bmp, see viewtopic.php?f=3&t=15643
imagecorpis

Re: transparent background - How! (solved!)

Post by imagecorpis »

Thanks! I was reading the documentation and also found that
"convert drawn.png -channel matte -separate +channel -negate mask_separate.png" also works for the same purpose.
Post Reply