<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Output a PNG image to either the browser or a file</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagepalettetotruecolor.html">imagepalettetotruecolor</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagepolygon.html">imagepolygon</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.imagepng" class="refentry"> <div class="refnamediv"> <h1 class="refname">imagepng</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imagepng</span> — <span class="dc-title">Output a PNG image to either the browser or a file</span></p> </div> <div class="refsect1 description" id="refsect1-function.imagepng-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">bool</span> <span class="methodname"><strong>imagepng</strong></span> ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$image</code></span> [, <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$quality</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$filters</code></span> ]]] )</div> <p class="para rdfs-comment"> Outputs or saves a <acronym title="Portable Network Graphics">PNG</acronym> image from the given <em><code class="parameter">image</code></em>. </p> </div> <div class="refsect1 parameters" id="refsect1-function.imagepng-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter"> image</code></em></span><dd> <p class="para">An image resource, returned by one of the image creation functions, such as <span class="function"><a href="function.imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>.</p></dd> </dt> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para">The path to save the file to. If not set or <strong><code>NULL</code></strong>, the raw image stream will be outputted directly.</p> <blockquote class="note"><p><strong class="note">Note</strong>: <p class="para"> <strong><code>NULL</code></strong> is invalid if the <em><code class="parameter">quality</code></em> and <em><code class="parameter">filters</code></em> arguments are not used. </p> </p></blockquote> </dd> </dt> <dt> <span class="term"><em><code class="parameter">quality</code></em></span> <dd> <p class="para"> Compression level: from 0 (no compression) to 9. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">filters</code></em></span> <dd> <p class="para"> Allows reducing the PNG file size. It is a bitmask field which may be set to any combination of the <em>PNG_FILTER_XXX</em> constants. <strong><code>PNG_NO_FILTER</code></strong> or <strong><code>PNG_ALL_FILTERS</code></strong> may also be used to respectively disable or activate all filters. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.imagepng-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure. </p> </div> <div class="refsect1 changelog" id="refsect1-function.imagepng-changelog"> <h3 class="title">Changelog</h3> <p class="para"> <table class="doctable informaltable"> <thead> <tr> <th>Version</th> <th>Description</th> </tr> </thead> <tbody class="tbody"> <tr> <td>5.1.3</td> <td> Added the <em><code class="parameter">filters</code></em> parameter. </td> </tr> <tr> <td>5.1.2</td> <td> Added the <em><code class="parameter">quality</code></em> parameter. </td> </tr> </tbody> </table> </p> </div> <div class="refsect1 examples" id="refsect1-function.imagepng-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="informalexample"> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefrompng</span><span style="color: #007700">(</span><span style="color: #DD0000">"test.png"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type: image/png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">imagepng</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 seealso" id="refsect1-function.imagepng-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="function"><a href="function.imagegif.html" class="function" rel="rdfs-seeAlso">imagegif()</a> - Output image to browser or file</span></li> <li class="member"> <span class="function"><a href="function.imagewbmp.html" class="function" rel="rdfs-seeAlso">imagewbmp()</a> - Output image to browser or file</span></li> <li class="member"> <span class="function"><a href="function.imagejpeg.html" class="function" rel="rdfs-seeAlso">imagejpeg()</a> - Output image to browser or file</span></li> <li class="member"> <span class="function"><a href="function.imagetypes.html" class="function" rel="rdfs-seeAlso">imagetypes()</a> - Return the image types supported by this PHP build</span></li> <li class="member"> <span class="function"><a href="function.imagesavealpha.html" class="function" rel="rdfs-seeAlso">imagesavealpha()</a> - Set the flag to save full alpha channel information (as opposed to single-color transparency) when saving PNG images</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagepalettetotruecolor.html">imagepalettetotruecolor</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagepolygon.html">imagepolygon</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>