Page 1 of 1

Output of Convert command to Blob

Posted: 2014-02-13T14:41:09-07:00
by Tony
I am using the following code in a Magic++ application...

Code: Select all

 MagickBooleanType status = ConvertImageCommand(image_info, args_count, args, NULL, exception);
Is it possible for the ConvertImageCommand to write its output to a Blob or use some other 'in memory' technique?
I am trying to avoid writing the output to disk via the command and then re-reading the output file into the application.
There are vague reference in some other posts concerning blobs, file descriptors, stdin/stdout and streams but I have been unable to locate a specific technique with examples.

Thanks.

Re: Output of Convert command to Blob

Posted: 2014-02-27T09:16:27-07:00
by spongemonkey
This sort of code isn't how to use the Magick++ API.

You'd do something like

Code: Select all

#include <Magick++>

using namespace Magick;
using namespace std;

...

// open an image
Image image("some_image.jpg");

// perhaps do something to the image
image.resize(Geometry(500,500));

// will hold the image data in memory rather than writing it to a file
Blob blob;

// write the resized image data to the blob in png format
image.write(&blob,"png");

// perhaps then we'll write it to disk
ofstream outFile;
	
outFile.open("was_once_held_in_memory_by_IM.png", ios::out | ios::binary);

// blob.data() returns a void* with the actual data, blob.length() tells you how much data is there
outFile.write((char*)blob.data(),blob.length());
outFile.close();
If you give more info about what you want to do I might be able to help more