<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.image.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.imagesavealpha.php',
    1 => 'imagesavealpha',
    2 => 'Whether to retain full alpha channel information when saving images',
  ),
  'up' => 
  array (
    0 => 'ref.image.php',
    1 => 'GD and Image Functions',
  ),
  'prev' => 
  array (
    0 => 'function.imagerotate.php',
    1 => 'imagerotate',
  ),
  'next' => 
  array (
    0 => 'function.imagescale.php',
    1 => 'imagescale',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/image/functions/imagesavealpha.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.imagesavealpha" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagesavealpha</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.3.2, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">imagesavealpha</span> &mdash; <span class="dc-title">Whether to retain full alpha channel information when saving images</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.imagesavealpha-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>imagesavealpha</strong></span>(<span class="methodparam"><span class="type"><a href="class.gdimage.php" class="type GdImage">GdImage</a></span> <code class="parameter">$image</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$enable</code></span>): <span class="type"><a href="language.types.singleton.php" class="type true">true</a></span></div>

  <p class="para rdfs-comment">
   <span class="function"><strong>imagesavealpha()</strong></span> sets the flag which determines whether to retain
   full alpha channel information (as opposed to single-color transparency)
   when saving images.
   This is only supported for image formats which support full alpha channel information,
   i.e. <code class="literal">PNG</code>, <code class="literal">WebP</code> and <code class="literal">AVIF</code>.
   <blockquote class="note"><p><strong class="note">Note</strong>: 
    <span class="simpara">
     <span class="function"><strong>imagesavealpha()</strong></span> is only meaningful for <code class="literal">PNG</code>
     images, since the full alpha channel is always saved for <code class="literal">WebP</code>
     and <code class="literal">AVIF</code>. It is not recommended to rely on this behavior,
     as it may change in the future. Thus, <span class="function"><strong>imagesavealpha()</strong></span>
     should be called deliberately also for <code class="literal">WebP</code> and
     <code class="literal">AVIF</code> images.
    </span>
   </p></blockquote>
  </p>
  <p class="para">
   Alphablending has to be disabled (<code class="code">imagealphablending($im, false)</code>)
   to retain the alpha-channel in the first place.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.imagesavealpha-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    <dt>
<code class="parameter">image</code></dt><dd><p class="para">A <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span> object, returned by one of the image creation functions,
such as <span class="function"><a href="function.imagecreatetruecolor.php" class="function">imagecreatetruecolor()</a></span>.</p></dd>
    
     <dt><code class="parameter">enable</code></dt>
     <dd>
      <p class="para">
       Whether to save the alpha channel or not. Defaults to <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>. 
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.imagesavealpha-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Always returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.imagesavealpha-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
 <td>8.0.0</td>
 <td>
  <code class="parameter">image</code> expects a <span class="classname"><a href="class.gdimage.php" class="classname">GdImage</a></span>
  instance now; previously, a valid <code class="literal">gd</code> <span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> was expected.
 </td>
</tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.imagesavealpha-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Basic <span class="function"><strong>imagesavealpha()</strong></span> Usage</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Load a png image with alpha channel<br /></span><span style="color: #0000BB">$png </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefrompng</span><span style="color: #007700">(</span><span style="color: #DD0000">'./alphachannel_example.png'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Turn off alpha blending<br /></span><span style="color: #0000BB">imagealphablending</span><span style="color: #007700">(</span><span style="color: #0000BB">$png</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Do desired operations<br /><br />// Set alpha flag<br /></span><span style="color: #0000BB">imagesavealpha</span><span style="color: #007700">(</span><span style="color: #0000BB">$png</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Output image to browser<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">$png</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.imagesavealpha-seealso">
  <h3 class="title">See Also</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.imagealphablending.php" class="function" rel="rdfs-seeAlso">imagealphablending()</a> - Set the blending mode for an image</span></li>
  </ul>
 </div>

</div><?php manual_footer($setup); ?>