downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/image.examples-watermark.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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 => 'en',
  ),
 
'this' =>
  array (
   
0 => 'image.examples-watermark.php',
   
1 => 'Adding watermarks to images using alpha channels',
  ),
 
'up' =>
  array (
   
0 => 'image.examples.php',
   
1 => 'Examples',
  ),
 
'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',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<div id="image.examples-watermark" class="section">
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 Adding watermarks to images using alpha channels</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Load&nbsp;the&nbsp;stamp&nbsp;and&nbsp;the&nbsp;photo&nbsp;to&nbsp;apply&nbsp;the&nbsp;watermark&nbsp;to<br /></span><span style="color: #0000BB">$stamp&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</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">//&nbsp;Set&nbsp;the&nbsp;margins&nbsp;for&nbsp;the&nbsp;stamp&nbsp;and&nbsp;get&nbsp;the&nbsp;height/width&nbsp;of&nbsp;the&nbsp;stamp&nbsp;image<br /></span><span style="color: #0000BB">$marge_right&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$marge_bottom&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$sx&nbsp;</span><span style="color: #007700">=&nbsp;</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&nbsp;</span><span style="color: #007700">=&nbsp;</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">//&nbsp;Copy&nbsp;the&nbsp;stamp&nbsp;image&nbsp;onto&nbsp;our&nbsp;photo&nbsp;using&nbsp;the&nbsp;margin&nbsp;offsets&nbsp;and&nbsp;the&nbsp;photo&nbsp;<br />//&nbsp;width&nbsp;to&nbsp;calculate&nbsp;positioning&nbsp;of&nbsp;the&nbsp;stamp.&nbsp;<br /></span><span style="color: #0000BB">imagecopy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">$sx&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$marge_right</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagesy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">)&nbsp;-&nbsp;</span><span style="color: #0000BB">$sy&nbsp;</span><span style="color: #007700">-&nbsp;</span><span style="color: #0000BB">$marge_bottom</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">imagesx</span><span style="color: #007700">(</span><span style="color: #0000BB">$stamp</span><span style="color: #007700">),&nbsp;</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">//&nbsp;Output&nbsp;and&nbsp;free&nbsp;memory<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-type:&nbsp;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">imagedestroy</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" />
     </div>
    </div>
   </div><p>
   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(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites