Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Image_Gallery and watermark


2 Posts   703 Views


2 October 2010 at 7:51am Community Member, 218 Posts

Hi guys,

I'm looking for the best solution to add watermarks to my image gallery:
and my watermark is stored here:

I've read all of the related threads on here (which look great) but im not much of a developer and don't really understand where I need to put the codes...

can anybody post a short tutorial for me? :)
im working with uncle cheese's Image_gallery

ANY help at all would be greatly appreciated.


4 October 2010 at 11:37pm Community Member, 218 Posts

do i do something like this

   public function Watermark(GD $gd) {
   // Read the watermark picture
   $watermark = imagecreatefrompng($URL . '/themes/Ace/images/watermark.png');
   $watermark_width = imagesx($watermark);
   $watermark_height = imagesy($watermark);

   // Read Full size Silverstripe image
   $imageToWatermark = imagecreatefromjpeg($this->URL);

   // Calculate sizes
   $size = getimagesize($this->URL);
   $dest_x = $size[0] - $watermark_width - 5;
   $dest_y = $size[1] - $watermark_height - 5;

   // Do transformations and save image in assets
   imagecopymerge($imageToWatermark, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 40);
   imagepng($imageToWatermark,$webroot . $this->filename . "_watermarked.png");
   // And this is the trick ;-) Create an object Silverstripe can work with....
   $GDoutput= new GD($webroot . $this->filename . "_watermarked.png");
   return $GDoutput;

where do i put this??