Hello everybody again,
so today I started working with charts as images rendered by PHP. I wanted
to ask what do you guys think about encoding images in the HTML using base64
like this:
<imgsrc="data:image/gif;base64,R0lGODlhUAA....j5+g4JADs=" />
I thought about these pros and cons.
First of all pros:
- no additional request to fetch the image from server.
- image generation script can return multiple values. For example the
image itself and the image map (later used for tooltips) can be returned.
Cons
- some overhead is introduced when encoding binary data into base64
format. On my experiment 46kB image was encoded into 60kB. (~30% overhead).
- Script execution is halted while the image generation is in progress.
This introduces slower response times for pages, which show charts. (If the
image is loaded in a "normal" way, in many browsers page is started being
rendered before images are received from the server). This problem can be
solved by writing rendered charts to disk. However almost all planned charts
are going to display dynamic data (query results, profiling data, query
statistics).
- Generated images can not be linked to externally. (hardly a problem for
PMA)
The only real problem that I see is the longer script execution times.
However all the charts will be generated only on user request, so we can
assume that the user knows that the chart is coming soon and expects to wait
a little bit more.
Both techniques are easy to implement. I have already images as base64
strings working. Changing this would be a matter of minutes.
What do you think?
Martynas