1

I recently began using Magick++ (C++ API for ImageMagick) with the goal of creating a website that could display randomly generated images. I am trying to write a CGI script which would create a JPEG Image, set the color of its pixels, and then return the image information as Content-type: image/jpg.

Reading through the documentation, I only find functions for writing image files to disk. I do not see one which would do what I am hoping to do, along the lines of std::cout << Image or std::cout << Blob

My goal is to be able to display the image generated by the script in a webpage, without needing to write the image to disk.

I know that PerlMagick has a display function which does what I am trying to do - I am wondering if I can do the same with Magick++.

4

1 回答 1

1

我认为您正在寻找 blob - Binary Large Objects。基本上,您创建一个 type 的图像Image和一个 type 的 blob Blob。您可以通过从文件读取或生成随机数据来填充图像,然后将图像写入 blob(对其进行编码),然后可以将其写入用户的浏览器。

请原谅我无用的 C/C++ 技能...

Image  image;
Blob   blob;

// set type to JPEG
image.magick("JPEG");   

// generate/read/fill image here
image.read("image.jpg");

// encode image as JPEG
image.write(&blob);   

// now send MIME type to browser
std::cout << "Content-type: image/jpeg" << CRLF;

// ... followed by blob
write(1,(char*)blob.data(),blob.length());
于 2015-06-06T17:00:06.750 回答