Page 1 of 1

Not Flattening When Saving JPG [SOLVED]

Posted: 2012-08-30T08:19:35-07:00
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;
}

Re: Not Flattening When Saving JPG

Posted: 2012-08-30T09:02:12-07:00
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.