GIF Image Compositing with Opacity? [magick++]

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
mankyd

GIF Image Compositing with Opacity? [magick++]

Post by mankyd »

I am sure this has been asked before but the search feature doesn't allow querying for "gif" :(

I've written a program generates an image based on my users' input, composites their input over top with a slight opacity, and outputs its as a jpeg. Most of the time, this works no problem (99% of my users upload jpegs or pngs)

The problem is that I have a user on my website that is trying to create an image from a gif (a gif with a transparent color, to be specific.) For whatever reason, when my program blended their image over top, it didn't pay heed to the opacity setting. It simply kept the transparent color of the gif and made everything else opaque. How do I fix this?

Code: Select all

if (_original_opacity != 0) {  //original opacity is set to 10
	_source_img->modifyImage();
	_source_img->opacity(int(TransparentOpacity * float(100 - _original_opacity) / 100.));
	_source_img->zoom(Geometry(out.columns(), out.rows()));
	out.composite(*_source_img, 0, 0, DissolveCompositeOp);
}

input: http://mozaiq.org/mozaiq/0/102.8724744.source.gif
erroneous output: http://mozaiq.org/mozaiq/0/102.8724744.9.jpg
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF Image Compositing with Opacity? [magick++]

Post by anthony »

If you don't want the transparency, you will need to overlay it on some background.
See IM Examples GIF file format, 'Solid background color'
http://www.imagemagick.org/Usage/formats/#bgnd

It may be blend is not understnding a 'index' image, so type using resting the images type.


Remember JPEG does NOT understand transparency, so don't have any when you are ready to save it.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply