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

ImageGallery and Watermark


6 Posts   2284 Views


22 July 2009 at 5:29am Community Member, 38 Posts

Hello UncleCheese,

is there a way to extend the existing image gallery, oder even the image upload field to add a watermark to each photo when it has been uploaded? That would preserve me from much work, when this can be done in the process of uploading...

Markus Alexander


22 July 2009 at 5:42am 4085 Posts

I'm sure there is. Plenty of sites do it, but it's complex work with the GD library. You might be able to find an open-source PHP class that does it for you.


22 July 2009 at 10:54pm (Last edited: 22 July 2009 10:55pm), Community Member, 787 Posts

did you search the forum ? I posted a (non-elegant) piece of code for that.....


1 September 2009 at 11:17pm Community Member, 21 Posts

Hey Fuzz10,
I am struggling to implement it into my website... I am wanting to make it add the watermark to all the large images (not the thumbnails)

Do I add that function into the page control for the gallery page? or into the gd.php file?
How do I call it on the page?

Thanks HEAPS for your help!

If you're too busy to explain it, if you just sent me the pages involved I'll be able to work the rest out :)



2 September 2009 at 12:34am Community Member, 787 Posts


Basically , what you want to do is extend the Image class and use that class to add images to your pages.

For more information : check out

You can add the new watermark code to the image class as well..... Good luck !


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

can anybody shed any more light on this?
im struggling to work out where to actually put the code.

im working with Uncle Cheese's Image_gallery.

do i apply the watermark when images are UPLOADED via the CMS, or is it when they are RENDERED?

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;