Page 1 of 1

GIF Transparency

Posted: 2007-03-12T23:23:15-07:00
by Vexxed
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;
}

Re: GIF Transparency

Posted: 2007-03-19T20:45:44-07:00
by anthony
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