GIF Transparency
Posted: 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!
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;
}