Write Animated GIFs to Blob

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Write Animated GIFs to Blob

Post by tc33 »

Hi,

Magick++ doesn't seem to write multi-image Images to a single blob. Regardless if the image has multiple sub-images, it always calls ImageToBlob, when it appears it should be calling ImagesToBlob instead, if needed. I'm guessing this applies to multi-page TIFFs, PDFs, and others as well?

Anyhoo, here's my wrapper around the Write method, perhaps something like this could be integrated into Magick++ to save someone else the headache later on:

Code: Select all

#include <Magick++.h>
#include <magick/blob.h>		// ImagesToBlob

// writes a magick image to the target blob
	void write_magick_img( Magick::Image& img, Magick::Blob& target )
	{
		if ( img.constImage()->next == NULL )  // has multiple images?
		{
			img.write( &target );  // forward to regular write method
		}
		else  // Magick++ doesn't write multiple image to blob, need to use blob.c / ImagesToBlob
		{
			img.adjoin( true );		// manually set adjoin param, not sure if this is needed
			size_t sz = 0;

			unsigned char* data = ImagesToBlob( img.constImageInfo(), img.image(), &sz, &img.image()->exception );
			target.updateNoCopy( data, sz, Magick::Blob::MallocAllocator );	// Magick::Blob takes ownership here

		}
	}	// write_magick_img
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Write Animated GIFs to Blob

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.2-4 Beta available by sometime tomorrow. Thanks.
tc33
Posts: 40
Joined: 2012-10-21T22:10:21-07:00
Authentication code: 67789

Re: Write Animated GIFs to Blob

Post by tc33 »

Awesome, thank you!
royxr
Posts: 4
Joined: 2017-05-02T22:28:30-07:00
Authentication code: 1151

Re: Write Animated GIFs to Blob

Post by royxr »

sorry to bother you. I have a problem write images (as gif) to blob, could you pls help me out?

I write the same vector<Magick::Image> frames to file and to blob, the to file part works fine, but when I write images to blob, it went wrong.

it seems it only write the first frame to blob. here is my code with comments. thanks

Code: Select all

    vector<Magick::Image> frames;
    int delay = 20;
    for(auto iter=taskList.begin(); iter != taskList.end(); ++iter){
    /* hide some codes here*/
      frames.push_back(*img);
    }
   [i] // write images to file, works fine[/i]
    Magick::writeImages(frames.begin(), frames.end(), "xxx.gif");
    Magick::Blob tmpBlob;
 [i]   // write images to blob, I later decode the data in blob,  and write it to yyy.gif. The gif file only contains the first frame image.[/i]
    Magick::writeImages(frames.begin(), frames.end(), &tmpBlob, true);
    // the length is far to small 
    LOG_DEBUG("blob data length: %d", tmpBlob.length());
royxr
Posts: 4
Joined: 2017-05-02T22:28:30-07:00
Authentication code: 1151

Re: Write Animated GIFs to Blob

Post by royxr »

magick wrote: 2013-02-04T04:07:44-07:00 We can reproduce the problem you posted and have a patch in ImageMagick 6.8.2-4 Beta available by sometime tomorrow. Thanks.
could you help me with this? I am using version 7.0.3-9 with Magick++ (writeImages of STL.h)
royxr
Posts: 4
Joined: 2017-05-02T22:28:30-07:00
Authentication code: 1151

Re: Write Animated GIFs to Blob

Post by royxr »

problem solved. the reason is that I forgot to add img->magick("gif").
Post Reply