carter has asked for the wisdom of the Perl Monks concerning the following question:

I have code to read LDAP to pull our a jpeg. The jpeg is in a string in perl. How can I output that string of binary data to the web page. I know I could write it and then generate the web page but wanted to avoid creating the jpg on the file system first.

Replies are listed 'Best First'.
Re: How to read JPEG and output to HTML
by bikeNomad (Priest) on Jul 25, 2001 at 09:43 UTC
    Just have a CGI (or other server-side Perl script) that, when called, outputs HTTP headers and content:

    my $jpeg = getTheJpeg(); binmode STDOUT; print "Content-Type: image-jpeg\r\n", "Content-Length: ", length($jpeg), "\r\n\r\n", $jpeg;

    The CGI is then pointed to by an IMG tag in your HTML.

    update: shortened print command for clarity