in reply to Incorporating On-The-Fly Graphics In CGI output
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:#!/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);
Netscape 4.7 on Linux showed the image without any problems. Opera did not. So results may vary.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>
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Incorporating On-The-Fly Graphics In CGI output
by revdiablo (Prior) on Mar 31, 2003 at 07:59 UTC |