Merge (watermark)

Applying a watermark (or merging) is done with the merge() method. You have to pass another image object, coordinates and opacity. If coordinates aren’t given, the image is merged at (0, 0). If opacity isn’t specified, value 100 is used.

Note: for images with alpha channel (PNG 24-bit with alpha channel), you have to use opacity=100, otherwise you’ll lose the alpha channel. In these cases, the alpha channel of the image specifies opacity.

An example of merge with opacity 30 to position 10, 10:

  1. $img = WideImage::load('pic.jpg');
  2. $watermark = WideImage::load('logo.jpg');
  3. $new = $img->merge($watermark, 10, 10, 30);

Merge operation supports smart coordinates, so you can easily place the watermark relative to the right or bottom edge:

  1. $img = WideImage::load('pic.jpg');
  2. $watermark = WideImage::load('logo.jpg');
  3. // logo.jpg is 50×30 in size
  4.  
  5. // place the logo directly in the center (x), 10px from bottom (y)
  6. $new = $img->merge($watermark, '50% – 25', '100% – 40', 50);
  7.  
  8. // or use alignment labels, it's prettier
  9. $new = $img->merge($watermark, 'center', 'bottom – 10', 50);

See also: merge demo.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Reddit
  • Tumblr
  • Twitter