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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

ImageGallery and Watermark

Go to End

6 Posts   2865 Views


Community Member, 38 Posts

22 July 2009 at 5:29am

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


Forum Moderator, 4102 Posts

22 July 2009 at 5:42am

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.


Community Member, 791 Posts

22 July 2009 at 10:54pm

Edited: 22/07/2009 10:55pm

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


Community Member, 21 Posts

1 September 2009 at 11:17pm

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 :)



Community Member, 791 Posts

2 September 2009 at 12:34am


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 !


Community Member, 219 Posts

4 October 2010 at 11:37pm

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;