Blame | Last modification | View Log | RSS feed
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><!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><code class="function">EncodeImage</code> returns the plot image as a string, usingone of three encodings. This function can be used when special processingof the plot image data is necessary, rather than the default behavior ofsending the image via standard output (usually to a browser), or writing itto a file. In particular, <code class="function">EncodeImage</code> can be used toembed a PHPlot image inside an HTML file without requiring a separate script.</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>Optional string indicating the encoding to use for the return value. Ifsupplied, it must be one of the following values:</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>No encoding - the raw data representing the imageis returned.</td></tr><tr><td>base64</td><td>Encodes the image data using base64 (RFC2045).</td></tr><tr><td>dataurl</td><td>Encodes the image data for a 'data:' URL scheme.This is the default. See notes below.</td></tr></tbody></table></div><p></p></dd></dl></div></div><div class="refsect1"><a id="idp1377687612"></a><h2>Return Value</h2><p>Returns the image data, using the indicated encoding.</p></div><div class="refsect1"><a id="idp1377688276"></a><h2>Notes</h2><p>The default value for <em class="parameter"><code>$encoding</code></em> is<code class="literal">dataurl</code>.</p><p><code class="literal">raw</code> encoding returns the image data. If the image fileformat was set to the default PNG, the return result would be a valid PNGfile if it was written to a file.</p><p><code class="literal">base64</code> encoding starts with the same data as<code class="literal">raw</code>, and encodes it as ASCII characters using the PHPfunction <code class="function">base64_encode</code> and returns the result.Note that the result is not broken into lines, as required by some applications.Use the PHP function <code class="function">chunk_split</code> if this is needed.</p><p><code class="literal">dataurl</code> encoding returns the image data suitable for use asthe value of the 'src' attribute in an HTML 'img' tag using the data URLscheme. This embeds the image into the HTML, and so it does not requirean external image file. The data URL scheme is defined by<a class="ulink" href="http://www.faqs.org/rfcs/rfc2397.html" target="_top">RFC 2397</a>.</p><div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Warning</h3><p>RFC 2397 makes it clear that the scheme is intended for embedding small images,and that there may be length limitations on the encoded data. However, thereare other applications (for example LibreOffice) that use the data URL schemefor large images. While it has been found to work with large images in themajor web browsers, testing in your own environment is recommended.</p></div><p></p><p>When using <code class="function">EncodeImage</code> to get the plot image, ratherthan letting PHPlot output the image to standard output or a file, you mustcall <a class="xref" href="SetPrintImage.html" title="SetPrintImage"><span class="refentrytitle">SetPrintImage</span></a><code class="literal">(False)</code> to prevent<a class="xref" href="DrawGraph.html" title="DrawGraph"><span class="refentrytitle">DrawGraph</span></a> from sending the image data to standard output.You should also call <a class="xref" href="SetFailureImage.html" title="SetFailureImage"><span class="refentrytitle">SetFailureImage</span></a><code class="literal">(False)</code>to prevent PHPlot from producing an unexpected image on standard output incase of a fatal error.</p><p>An example of using the <code class="literal">dataurl</code> encoding is:</p><pre class="programlisting">$plot = new PHPlot(800, 600);$plot->SetPrintImage(False); // Do not output the image... // Plot settings, data, etc.$plot->DrawGraph(); // Make the plot but do not output itecho "<img src=\"" . $plot->EncodeImage() . "\">\n";</pre><p></p><p>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>.</p></div><div class="refsect1"><a id="idp1377698364"></a><h2>History</h2><p>This function was added in PHPlot-5.5.0.</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>