Not Flattening When Saving JPG [SOLVED]

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
insomniacp
Posts: 11
Joined: 2012-08-20T09:03:33-07:00
Authentication code: 67789

Not Flattening When Saving JPG [SOLVED]

Post by insomniacp »

Hi,
Using the below code shows that when converting a png with alpha channels to a jpg image the alpha channels are not flattened but simply removed. I am wondering if there is a way to flatten the pixels before or during conversion so that the semi transparent pixels still retain the color they appear to have but are fully opaque due to being in a jpg. I could not locate any way to do this manually before saving so I am unsure how to proceed if I need to write my own function or not. I know ImageMagick itself does have the ability to flatten so I am assuming that it is accessible through the magick++ interface.

Code: Select all

#include <Magick++.h> 
#include <iostream>
using namespace std;
using namespace Magick;
int main()
{
	Image test;
	string url = "http://render.skreened.com/render-product/b/w/z/bwzjevnlbygsrhqwwxko/b.American-Apparel-Unisex-Organic-Tee.Cinder.w380h440z1.png";
	try{
		test.read(url);
	} catch(Exception e)
	{
		cout <<e.what()<<endl;
	}
	if(test.columns()>1)
	{
		try{
		cout <<"writing file"<<endl;
		test.write("test.jpg");
		} catch(Exception e)
		{
			cout <<"something bad happened "<<e.what()<<endl;
		}
	}
	cout <<"done with program"<<endl;
	return 0;
}
Last edited by insomniacp on 2012-08-30T09:24:37-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Not Flattening When Saving JPG

Post by magick »

You need to call MagickCore::MergeImageLayers() with MagickCore::FlattenLayer. In the mean-time we'll a Magick++ mergeLayers() method in the next point release of ImageMagick.
Post Reply