Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
The foregoing comments are mostly true, but not entirely. There is the data: URI, but not all browsers support it. It allows image data to be embedded directly in the HTML, and there is even a Perl module that makes it easy to use in a CGI environment. The following code will generate some text and an image consisting of a red square with a blue-outline square inside of it:
#!/usr/bin/perl use strict; use URI; use GD; my $img = GD::Image->new(100,100); my $red = $img->colorAllocate(255,0,0); my $blue = $img->colorAllocate(0,0,255); $img->rectangle(40,40,59,59,$blue); my $uri = URI->new("data:"); $uri->media_type("image/png"); $uri->data($img->png); print "Content-type:text/html\n\n"; print "<html>\n"; print "<h3>Testing inline image data</h3>"; print qq(<img src="$uri" alt="Didn't work."></html>\n);
This is a CGI script, even though I didn't actually use CGI, as it didn't help to illustrate the point. Anyway, the code produces this output:
Content-type:text/html <html> <h3>Testing inline image data</h3><img src="data:image/png;base64,iVBO +Rw0KGgoAAAANSUhEUgAAAGQAAABkAQMAAABKLAcXAAAABlBMVEX/AAAAAP9sof2OAAAAI +UlEQVR4nGNgGAWjgFTw//8HJF4Dg8CI5aGGxCgYBcQBAMULD/2Zt2wmAAAAAElFTkSuQm +CC" alt="Didn't work."></html>
Netscape 4.7 on Linux showed the image without any problems. Opera did not. So results may vary.

Also, there is apparently some restriction on the maximum size of such an embedded image, but so far I've not been able to determine what that is. Maybe someone else will know.

One would think that something could be done with the multipart/mixed MIME type. This is how mixed content is included in email messages, but so far my efforts to make this work with a browser have come up dry. I'm with you, though. It seems idiotic to require a separate request for data that could just as easily be included with the main document.

Update: Since images don't seem to be permitted in the SOPW nodes, I've included a sample similar to the above on my home node: Dr. Mu


In reply to Re: Incorporating On-The-Fly Graphics In CGI output by Dr. Mu
in thread Incorporating On-The-Fly Graphics In CGI output by lacertus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2018-07-20 22:28 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (441 votes). Check out past polls.

      Notices?