Mailing List

Flat
Interesting image problem for FF and Chrome
User: mcholste
Date: 8/6/2010 1:34 pm
Views: 800
Rating: 0
Ok, so I'm working on this Perl code that takes various kinds of POST
data (SQL queries and DSN info, raw JSON, and CSV) and creates a graph
out of it.  I've been using different libraries, but I have working
code for the Chart::Clicker library as well as Open Flash Chart.
Here's the problem: Firefox and Chrome won't let you save the images
because they pointlessly re-download the URL listed in the src
attribute of the img element verbatim, which in my case is a POST.
They do this even when the image is the only thing on the page and the
MIME type is image.  That means that a right-click save-as is
effectively broken.  Sure, you can copy image and paste it into MS
Paint, but that is ridiculous.

I was hoping that the Save As feature in Open Flash Chart would do
some Flash magic, but sadly it implements a POST back to an arbitrary
CGI page of Base64-encoded image which your CGI then has to display,
so I'm right back where I started.

Has anyone run into this before?

--Martin
Re: Interesting image problem for FF and Chrome
User: mcholste
Date: 8/8/2010 3:20 pm
Views: 0
Rating: 0
Ok, I'm going to reply to my own question here with the solution in
case it helps anyone else out:

There is a little-known feature in HTML IMG tags that allows you to
specify that the data is base-64 encoded.  So, you can actually render
and image from base-64 text directly from the DOM like this:

var imgData = document.getElementById('open_flash_chart').get_img_binary();
//base-64 encoded raw PNG image
var imgElement = document.createElement('img');
imgElement.src = 'data:image/png;base64,' + imgdata;
document.body.appendChild(imgElement);

This will render an image directly to the document with all of the
image data embedded in the src attribute, which means there's no need
to have it go to an external source for its contents.  This works
nicely with my POST problem, because I can have the callback function
of my AJAX post function render the image directly, complete with
standard "Save As..." functionality.  Just have your Perl CGI page
return base-64 encoded PNG instead of the actual PNG.

I haven't tested this in IE, but it works in FF and Chrome.

--Martin

On Fri, Aug 6, 2010 at 1:34 PM,   wrote:
> mcholste wrote:
>
> Ok, so I'm working on this Perl code that takes various kinds of POST
> data (SQL queries and DSN info, raw JSON, and CSV) and creates a graph
> out of it.  I've been using different libraries, but I have working
> code for the Chart::Clicker library as well as Open Flash Chart.
> Here's the problem: Firefox and Chrome won't let you save the images
> because they pointlessly re-download the URL listed in the src
> attribute of the img element verbatim, which in my case is a POST.
> They do this even when the image is the only thing on the page and the
> MIME type is image.  That means that a right-click save-as is
> effectively broken.  Sure, you can copy image and paste it into MS
> Paint, but that is ridiculous.
>
> I was hoping that the Save As feature in Open Flash Chart would do
> some Flash magic, but sadly it implements a POST back to an arbitrary
> CGI page of Base64-encoded image which your CGI then has to display,
> so I'm right back where I started.
>
> Has anyone run into this before?
>
> --Martin
>
> View Online
>
> Madison Area Perl Mongers - MadMongers
> http://www.madmongers.org
>
PreviousNext
Madison Area Perl Mongers