using stream to send raw image to browser

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Posts: 14
Joined: 2011-02-15T03:16:59-07:00
Authentication code: 8675308

using stream to send raw image to browser

Post by sssddd »

I was trying to use "stream" program to dynamically load a portion of a large image and send it back to browser for display. I thought I could do this by passing the stream output to client browser without saving temp files etc. (using passthru() in php and send data via XMLHttpRequest to client side).

To test it, I tried to run "stream -map rgb -storage-type char -extract 10x10+5+5 test.png -" on command line, trying to see what it outputs. But it didn't seem to output anything to screen, as if it just spits out some blank lines. See the following:

root@plato:/home/src# stream -map rgb -storage-type char -extract 10x10+5+5 test.png -

Anyway, in php, I did:
header("Content-type: image/png");
encode_base64(passthru("stream -map rgb -storage-type char -extract 10x10+5+5 test.png -"));

At client side, I found the data returned from php looks something like this:
"<img src="data:image/png;base64,����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������"/>"

Note the weird characters in <img> data is the responseText from php. This is definitely wrong.

What command should I use to output the raw image data? Or am I totally on the wrong track?