Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not an issue with the application code, it's with the watermark image (PNG) itself.</p> <p>A lot of watermark examples/tutorials say to use a PNG-24 watermark, but according to a blog I've just read, they say that <code>imagecopymerge</code> does not deal with PNG-24 files very well, therefore, use PNG-8 and some special 'Save for Web' settings. I did this and it works fine now.</p> <p>Here is the relevant section about PNG types from <a href="http://salman-w.blogspot.com/2008/11/watermark-your-images-with-another.html" rel="nofollow">this blog</a>:</p> <blockquote> <p>The watermark image should be in one of the following recommended formats:</p> <ul> <li>PNG-8 (recommended)<br> Colors: 256 or less<br> Transparency: On/Off</li> <li>GIF<br> Colors: 256 or less<br> Transparency: On/Off</li> <li>JPEG<br> Colors: True color<br> Transparency: n/a</li> </ul> <p>The imagecopymerge function does not properly handle the PNG-24 images; it is therefore not recommended.</p> <p>If you are using Adobe Photoshop to create watermark images, it is recommended that you use "Save for Web" command with the following settings:</p> <pre class="lang-none prettyprint-override"><code>File Format: PNG-8, non-interlaced Color Reduction: Selective, 256 colors Dithering: Diffusion, 88% Transparency: On, Matte: None Transparency Dither: Diffusion Transparency Dither, 100% </code></pre> </blockquote> <hr> <p>And for other's benefits, this is the watermark code I have that works:</p> <pre><code>&lt;? $masterURL = 'mydomain.com/myImage.jpg'; header('content-type: image/jpeg'); $watermark = imagecreatefrompng('watermark.png'); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); $image = imagecreatetruecolor($watermark_width, $watermark_height); $image = imagecreatefromjpeg($masterURL); $size = getimagesize($masterURL); $dest_x = $size[0] - $watermark_width - 5; $dest_y = $size[1] - $watermark_height - 5; imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); imagejpeg($image); imagedestroy($image); imagedestroy($watermark); ?&gt; </code></pre> <p>After a bit more reading (<a href="http://salman-w.blogspot.com/2008/11/watermark-your-images-with-another.html?showComment=1345978146955#c3947848442031211061" rel="nofollow">this comment</a> on the same article), I found out that you CAN use PNG-24 watermarks but with <code>imagecopy</code> instead of <code>imagecopymerge</code>. You can replace this line:</p> <pre><code>imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); </code></pre> <p>with this one:</p> <pre><code>imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height); </code></pre> <p>Using <code>imagecopymerge</code> with PNG-8 watermarks is quite good for 'on-the-fly' watermarking, as the watermark file is tiny. If you do watermarking 'behind-the-scenes', it doesn't really matter about file size and you can get much better quality from the PNG-24 watermark, using <code>imagecopy</code>.</p> <p>I hope this helps the confused watermarkers out there.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload