Page 1 of 1

Allways black transparency in JPEG images

Posted: 2007-09-01T20:03:19-07:00
by MacStrix
Hello,

I have an image with transparency. And I want to save it as JPEG. I am using C. Everything works fine, except that transparent image places are black in output image. And I could not figure out how to change it, lets say to white.

Tried this:

Code: Select all

PixelWand *myPixelWand = NewPixelWand();
		PixelSetColor(myPixelWand,"rgba(255,255,255,255)");
		PixelSetOpacity(myPixelWand, 1.0); // tried 0.0 and 1.0
		MagickSetImageMatteColor(saveWand, myPixelWand);
		DestroyPixelWand(myPixelWand);
Does not work.

Code: Select all

PixelWand *myPixelWand = NewPixelWand();
		PixelSetColor(myPixelWand,"rgba(255,255,255,255)");
		PixelSetOpacity(myPixelWand, 1.0); // tried 0.0 and 1.0
		MagickSetImageBackgroundColor(saveWand, myPixelWand);
		DestroyPixelWand(myPixelWand);
Does not work also.

By the way: MagickGetImageMatte(saveWand) returns MagickTrue;

Any help would be very appreciate.

p.s.using ImageMagick 6.3.4

Re: Allways black transparency

Posted: 2007-09-02T11:00:44-07:00
by MacStrix
Here are files I am using:

source: http://img250.imageshack.us/img250/1439 ... e01rj1.png

result: http://img235.imageshack.us/img235/1918 ... e08vv4.jpg

Black area of result image should be white (in my case).

Re: Allways black transparency in JPEG images

Posted: 2007-09-03T21:18:28-07:00
by el_supremo
This will do it:

Code: Select all

convert input.png ( +clone -channel a -separate -negate ) +swap -composite output.jpg
It extracts the matte channel, negates it so that what was transparent is now white and then composites the original png over the top.
If you want a colour other than white, you'd have to replace the white in the negated matte with something else. I'm not sure how to do that though (yet).
Pete

Re: Allways black transparency in JPEG images

Posted: 2007-09-05T20:27:20-07:00
by anthony
Actually the simplest way is to -flatten the image before saving to JPG.

Code: Select all

convert image.png  -background white -flatten image.jpg

Re: Allways black transparency in JPEG images

Posted: 2007-09-06T08:09:56-07:00
by el_supremo
Of course! Thanks Anthony.

Pete