98 |
- |
1 |
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
|
|
|
2 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><title>EncodeImage</title><link rel="stylesheet" type="text/css" href="phplotdoc.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="PHPlot Reference Manual" /><link rel="up" href="reference.html" title="PHPlot Function Reference" /><link rel="prev" href="DrawMessage.html" title="DrawMessage" /><link rel="next" href="EndStream.html" title="EndStream" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">EncodeImage</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="DrawMessage.html">Prev</a> </td><th width="60%" align="center">PHPlot Function Reference</th><td width="20%" align="right"> <a accesskey="n" href="EndStream.html">Next</a></td></tr></table><hr /></div><div class="refentry"><a id="EncodeImage"></a><div class="titlepage"></div><div class="refnamediv"><h2><span class="refentrytitle">EncodeImage</span></h2><p>EncodeImage — Returns the plot image data</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">$plot->EncodeImage([<span class="optional"><em class="parameter"><code>$encoding</code></em></span>])</pre></div><div class="refsect1"><a id="idp1377679748"></a><h2>Description</h2><p>
|
|
|
3 |
<code class="function">EncodeImage</code> returns the plot image as a string, using
|
|
|
4 |
one of three encodings. This function can be used when special processing
|
|
|
5 |
of the plot image data is necessary, rather than the default behavior of
|
|
|
6 |
sending the image via standard output (usually to a browser), or writing it
|
|
|
7 |
to a file. In particular, <code class="function">EncodeImage</code> can be used to
|
|
|
8 |
embed a PHPlot image inside an HTML file without requiring a separate script.
|
|
|
9 |
</p></div><div class="refsect1"><a id="idp1377681436"></a><h2>Parameters</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="replaceable"><code>$encoding</code></em></span></dt><dd><p>
|
|
|
10 |
Optional string indicating the encoding to use for the return value. If
|
|
|
11 |
supplied, it must be one of the following values:
|
|
|
12 |
</p><div class="informaltable"><table summary="Available encoding types" border="1"><colgroup><col class="c1" /><col class="c2" /></colgroup><thead><tr><th>Encoding</th><th>Description</th></tr></thead><tbody><tr><td>raw</td><td>
|
|
|
13 |
No encoding - the raw data representing the image
|
|
|
14 |
is returned.
|
|
|
15 |
</td></tr><tr><td>base64</td><td>
|
|
|
16 |
Encodes the image data using base64 (RFC2045).
|
|
|
17 |
</td></tr><tr><td>dataurl</td><td>
|
|
|
18 |
Encodes the image data for a 'data:' URL scheme.
|
|
|
19 |
This is the default. See notes below.
|
|
|
20 |
</td></tr></tbody></table></div><p>
|
|
|
21 |
</p></dd></dl></div></div><div class="refsect1"><a id="idp1377687612"></a><h2>Return Value</h2><p>
|
|
|
22 |
Returns the image data, using the indicated encoding.
|
|
|
23 |
</p></div><div class="refsect1"><a id="idp1377688276"></a><h2>Notes</h2><p>
|
|
|
24 |
The default value for <em class="parameter"><code>$encoding</code></em> is
|
|
|
25 |
<code class="literal">dataurl</code>.
|
|
|
26 |
</p><p>
|
|
|
27 |
<code class="literal">raw</code> encoding returns the image data. If the image file
|
|
|
28 |
format was set to the default PNG, the return result would be a valid PNG
|
|
|
29 |
file if it was written to a file.
|
|
|
30 |
</p><p>
|
|
|
31 |
<code class="literal">base64</code> encoding starts with the same data as
|
|
|
32 |
<code class="literal">raw</code>, and encodes it as ASCII characters using the PHP
|
|
|
33 |
function <code class="function">base64_encode</code> and returns the result.
|
|
|
34 |
Note that the result is not broken into lines, as required by some applications.
|
|
|
35 |
Use the PHP function <code class="function">chunk_split</code> if this is needed.
|
|
|
36 |
</p><p>
|
|
|
37 |
<code class="literal">dataurl</code> encoding returns the image data suitable for use as
|
|
|
38 |
the value of the 'src' attribute in an HTML 'img' tag using the data URL
|
|
|
39 |
scheme. This embeds the image into the HTML, and so it does not require
|
|
|
40 |
an external image file. The data URL scheme is defined by
|
|
|
41 |
<a class="ulink" href="http://www.faqs.org/rfcs/rfc2397.html" target="_top">RFC 2397</a>.
|
|
|
42 |
</p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>
|
|
|
43 |
RFC 2397 makes it clear that the scheme is intended for embedding small images,
|
|
|
44 |
and that there may be length limitations on the encoded data. However, there
|
|
|
45 |
are other applications (for example LibreOffice) that use the data URL scheme
|
|
|
46 |
for large images. While it has been found to work with large images in the
|
|
|
47 |
major web browsers, testing in your own environment is recommended.
|
|
|
48 |
</p></div><p>
|
|
|
49 |
</p><p>
|
|
|
50 |
When using <code class="function">EncodeImage</code> to get the plot image, rather
|
|
|
51 |
than letting PHPlot output the image to standard output or a file, you must
|
|
|
52 |
call <a class="xref" href="SetPrintImage.html" title="SetPrintImage"><span class="refentrytitle">SetPrintImage</span></a><code class="literal">(False)</code> to prevent
|
|
|
53 |
<a class="xref" href="DrawGraph.html" title="DrawGraph"><span class="refentrytitle">DrawGraph</span></a> from sending the image data to standard output.
|
|
|
54 |
You should also call <a class="xref" href="SetFailureImage.html" title="SetFailureImage"><span class="refentrytitle">SetFailureImage</span></a><code class="literal">(False)</code>
|
|
|
55 |
to prevent PHPlot from producing an unexpected image on standard output in
|
|
|
56 |
case of a fatal error.
|
|
|
57 |
</p><p>
|
|
|
58 |
An example of using the <code class="literal">dataurl</code> encoding is:
|
|
|
59 |
</p><pre class="programlisting">$plot = new PHPlot(800, 600);
|
|
|
60 |
$plot->SetPrintImage(False); // Do not output the image
|
|
|
61 |
... // Plot settings, data, etc.
|
|
|
62 |
$plot->DrawGraph(); // Make the plot but do not output it
|
|
|
63 |
echo "<img src=\"" . $plot->EncodeImage() . "\">\n";
|
|
|
64 |
</pre><p>
|
|
|
65 |
</p><p>
|
|
|
66 |
A more complete example can be found in <a class="xref" href="ex-encodeimage.html" title="5.39. Example - Embedding Image with EncodeImage">Section 5.39, “Example - Embedding Image with EncodeImage”</a>.
|
|
|
67 |
</p></div><div class="refsect1"><a id="idp1377698364"></a><h2>History</h2><p>
|
|
|
68 |
This function was added in PHPlot-5.5.0.
|
|
|
69 |
</p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="DrawMessage.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="reference.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="EndStream.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">DrawMessage </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> EndStream</td></tr></table></div></body></html>
|