Using Magick++ with CGI to set the SRC of an IMG

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
jonotrain
Posts: 12
Joined: 2015-06-07T21:20:12-07:00
Authentication code: 6789

Using Magick++ with CGI to set the SRC of an IMG

Post by jonotrain » 2015-06-07T21:30:04-07:00

I am trying to create a CGI program capable of generating the data which will provide the source of an image. I do not want to generate an image file then display that file, but rather output the information as image/jpg.

I have written a program which I believe can send out the image information, but when I set it as the source of an image, nothing is displayed in the browser. My html is simple:

<img src = "script.cgi?parameter=1">

And the script uses Magick++ to generate an image and output its data. (For a variety of reasons, it is not possible for me to use PerlMagick, although I know it has some functions designed for CGI. I am working with multiprecision integers and perl is too slow.) Here is the part of the CGI which attempts to output the data:

Image babel( Geometry(640, 416), Color(MaxRGB, MaxRGB, MaxRGB, 0));
babel.magick("JPEG");
//set contents of Image pixels
Blob bablob;
babel.write(&bablob,"JPEG");

std::ostringstream streampunk;

streampunk.write((char*)bablob.data(),bablob.length());

std::cout << "Content-type: image/jpg\n\n";
std::cout << streampunk.str();

When I navigate to the html page, the cgi program runs, but no image appears in the browser when it finishes. I tried outputting the contents of the string stream in a command terminal to see what I was getting, and i got what i would expect - a bunch of non-ASCII characters. I'm hoping for some help towards getting programmatically generated image data to display on a webpage.

jonotrain
Posts: 12
Joined: 2015-06-07T21:20:12-07:00
Authentication code: 6789

Re: Using Magick++ with CGI to set the SRC of an IMG

Post by jonotrain » 2015-06-08T14:28:10-07:00

Nevermind - this code is working now. I was handling the parameters incorrectly

Post Reply