<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/image.examples.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'image.examples-watermark.php',
    1 => 'Adding watermarks to images using alpha channels',
    2 => 'Adding watermarks to images using alpha channels',
  ),
  'up' => 
  array (
    0 => 'image.examples.php',
    1 => 'Esempi',
  ),
  'prev' => 
  array (
    0 => 'image.examples-png.php',
    1 => 'PNG creation with PHP',
  ),
  'next' => 
  array (
    0 => 'image.examples.merged-watermark.php',
    1 => 'Using imagecopymerge to create a translucent watermark',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/image/examples.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="image.examples-watermark" class="section">
  <h2 class="title">Adding watermarks to images using alpha channels</h2>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Adding watermarks to images using alpha channels</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 the stamp and the photo to apply the watermark to<br /></span><span style="color: #0000BB">$stamp </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefrompng</span><span style="color: #007700">(</span><span style="color: #DD0000">'stamp.png'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefromjpeg</span><span style="color: #007700">(</span><span style="color: #DD0000">'photo.jpeg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Set the margins for the stamp and get the height/width of the stamp image<br /></span><span style="color: #0000BB">$marge_right </span><span style="color: #007700">= </span><span style="color: #0000BB">10</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$marge_bottom </span><span style="color: #007700">= </span><span style="color: #0000BB">10</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sx </span><span style="color: #007700">= </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$sy </span><span style="color: #007700">= </span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Copy the stamp image onto our photo using the margin offsets and the photo <br />// width to calculate positioning of the stamp. <br /></span><span style="color: #0000BB">imagecopy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">$stamp</span><span style="color: #007700">, </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">) - </span><span style="color: #0000BB">$sx </span><span style="color: #007700">- </span><span style="color: #0000BB">$marge_right</span><span style="color: #007700">, </span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">) - </span><span style="color: #0000BB">$sy </span><span style="color: #007700">- </span><span style="color: #0000BB">$marge_bottom</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">), </span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// Output<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 /></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">?&gt;</span></span></code></div>
    </div>

    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-watermarks.png" alt="Adding watermarks to images using alpha channels" width="320" height="240" />
     </div>
    </div>
   </div>
   This example is a common way to add watermarks and stamps to photos and 
   copyrighted images. Note that the presence of an alpha channel in the 
   stamp image as the text is anti-aliased. This is preserved during copying.
  </p>
 </div><?php manual_footer($setup); ?>