GIF Transparency

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Vexxed

GIF Transparency

Post by Vexxed » 2007-03-12T23:23:15-07:00

I'm attempting to use Magick++ and there isn't a forum here for it, so it looked like this was the closest one ...

I'm trying to use ImageMagick to take a large image that contains a grid of images (say, 3 x 6 tiles) and turn it into a long strip of an images (1x18 tiles). The input and output are both in GIF format and contain transparency. I've got the image getting resized and the interior images (tiles) copied into their new places within the large strip image, but the transparency is being lost in the copy. I suspect I need to get "output" to be cleared to transparent before doing the copy but I haven't been able to figure out how to do that yet. I've included a copy of the source code, and could really use some help.

Thanks!

Code: Select all

#include <Magick++.h>
#include <string>
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

using namespace Magick;

int main( int argc, char ** argv)
{
	if(argc < 4)
		return -1;

	// Initialize ImageMagick install location for Windows
	InitializeMagick(argv[0]);


	try {
		Image input;
		input.read(argv[1]);
		int width = input.baseColumns();
		int height = input.baseRows();
		int tilesX = atoi(argv[3]);
		int tilesY = atoi(argv[4]);

		int tileWidth = width / tilesX;
		int tileHeight = height / tilesY;

		int tileCount = tilesX * tilesY;

		Image output;
		output.size(Geometry(tileWidth, tileHeight * tilesX * tilesY));
		output.magick("GIF");

		int lastTile = 0;
		for(int i = 0; i < tilesY; ++i)
		{
			for(int j = 0; j < tilesX; ++j)
			{
				Image tmp = input;
				tmp.crop(Geometry(tileWidth, tileHeight, j * tileWidth, i * tileHeight));
				output.composite(tmp, 0, lastTile * tileHeight, OverCompositeOp);
				lastTile++;
			}
		}

		output.write(argv[2]);
	}
	catch( exception &error_ )
	{
		cout << "Caught exception: " << error_.what() << endl;
		return 1;
	}

	return 0;
}

User avatar
anthony
Posts: 8878
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF Transparency

Post by anthony » 2007-03-19T20:45:44-07:00

Suggestion, try doing it from the command line, then convert that into magick++
Assuming image is 300x300 pixels (each tile is 100 pixels) then...

Code: Select all

convert  image_in-array.gif  -crop 100x100 +repage +append   images_in_line.gif
that should be a lot easier to code up in Magick! :D
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply