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>5.39. Example - Embedding Image with 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="examples.html" title="Chapter 5. PHPlot Examples" /><link rel="prev" href="ex-xtickanchor.html" title="5.38. Example - Hourly Data Using X Tick Anchor" /><link rel="next" href="ex-bubbles1.html" title="5.40. Example - Bubbles Plot" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">5.39. Example - Embedding Image with EncodeImage</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ex-xtickanchor.html">Prev</a> </td><th width="60%" align="center">Chapter 5. PHPlot Examples</th><td width="20%" align="right"> <a accesskey="n" href="ex-bubbles1.html">Next</a></td></tr></table><hr /></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="ex-encodeimage"></a>5.39. Example - Embedding Image with EncodeImage</h2></div></div></div><p>
|
|
|
3 |
This example shows how <a class="xref" href="EncodeImage.html" title="EncodeImage"><span class="refentrytitle">EncodeImage</span></a> can be used to
|
|
|
4 |
embed a PHPlot image inside an HTML file using the 'data:' URL scheme.
|
|
|
5 |
Note: This feature was added in PHPlot-5.5.0.
|
|
|
6 |
</p><p>
|
|
|
7 |
This is the same plot as <a class="xref" href="ex-lines2.html" title="5.2. Example - Line Plot: Functions">Section 5.2, “Example - Line Plot: Functions”</a>, except instead of
|
|
|
8 |
producing the image on standard output, this script embeds the image in an HTML
|
|
|
9 |
page, which is produced on standard output. The screenshot below shows how the
|
|
|
10 |
web page looks in Firefox.
|
|
|
11 |
</p><div class="example"><a id="example-encodeimage"></a><p class="title"><strong>Example 5.39. Embedding Image with EncodeImage (Browser screenshot)</strong></p><div class="example-contents"><div class="informalfigure"><div class="mediaobject"><img src="images/encodeimage.png" alt="Web Page With Embedded Image" /></div></div><pre class="programlisting"><?php
|
|
|
12 |
# PHPlot Example: Using 'data:' URL scheme to embed an image
|
|
|
13 |
# Unlike other examples, this outputs a complete HTML page with embedded image.
|
|
|
14 |
require_once 'phplot.php';
|
|
|
15 |
|
|
|
16 |
# Generate data for: Y1 = sin(x), Y2 = cos(x)
|
|
|
17 |
$end = M_PI * 2.0;
|
|
|
18 |
$delta = $end / 20.0;
|
|
|
19 |
$data = array();
|
|
|
20 |
for ($x = 0; $x <= $end; $x += $delta)
|
|
|
21 |
$data[] = array('', $x, sin($x), cos($x));
|
|
|
22 |
|
|
|
23 |
$plot = new PHPlot(800, 600);
|
|
|
24 |
$plot->SetFailureImage(False); // No error images
|
|
|
25 |
$plot->SetPrintImage(False); // No automatic output
|
|
|
26 |
$plot->SetImageBorderType('plain');
|
|
|
27 |
$plot->SetPlotType('lines');
|
|
|
28 |
$plot->SetDataType('data-data');
|
|
|
29 |
$plot->SetDataValues($data);
|
|
|
30 |
$plot->SetTitle('Line Plot, Sin and Cos - Embedded Image');
|
|
|
31 |
$plot->SetLegend(array('sin(t)', 'cos(t)'));
|
|
|
32 |
$plot->SetPlotAreaWorld(0, -1, 6.8, 1);
|
|
|
33 |
$plot->SetXDataLabelPos('none');
|
|
|
34 |
$plot->SetXTickIncrement(M_PI / 8.0);
|
|
|
35 |
$plot->SetXLabelType('data');
|
|
|
36 |
$plot->SetPrecisionX(3);
|
|
|
37 |
$plot->SetYTickIncrement(0.2);
|
|
|
38 |
$plot->SetYLabelType('data');
|
|
|
39 |
$plot->SetPrecisionY(1);
|
|
|
40 |
$plot->SetDrawXGrid(True);
|
|
|
41 |
$plot->SetDrawYGrid(True);
|
|
|
42 |
$plot->DrawGraph();
|
|
|
43 |
|
|
|
44 |
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
|
|
45 |
"http://www.w3.org/TR/html4/loose.dtd">
|
|
|
46 |
<html>
|
|
|
47 |
<head>
|
|
|
48 |
<title>PHPlot Example - Inline Image</title>
|
|
|
49 |
</head>
|
|
|
50 |
<body>
|
|
|
51 |
<h1>PHPlot Example - Inline Image</h1>
|
|
|
52 |
<p>This is a plot of sin() and cos().</p>
|
|
|
53 |
<img src="<?php echo $plot->EncodeImage();?>" alt="Plot Image">
|
|
|
54 |
</body>
|
|
|
55 |
</html>
|
|
|
56 |
</pre></div></div><br class="example-break" /></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ex-xtickanchor.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="examples.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ex-bubbles1.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">5.38. Example - Hourly Data Using X Tick Anchor </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 5.40. Example - Bubbles Plot</td></tr></table></div></body></html>
|