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.

Archive /

Our old forums are still available as a read-only archive.

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

Watermark on uploaded image

Go to End

4 Posts   3031 Views


Community Member, 8 Posts

18 May 2007 at 10:05am

i want to add a watermark to a uploaded image. Any idea?
I have a class to watermark the image, but i can't figure it out where
to insert the watermark method.
it looks like
$thumb=new Thumbnail($filename);
Where i need to insert this snippet, to add the watermark to the uploaded image
from the cms.



Community Member, 791 Posts

27 August 2008 at 2:16am

Old message, but it resembles my question.

I'd like to manipulate uploaded images myself using GD (I need to watermark them). But since the Silverstripe images are wrapped in the (silverstripe) GD class, I can't figure out where to "hook" my watermark code.

Can anyone give me some pointers ? Thanks !


Community Member, 21 Posts

13 November 2008 at 7:44pm

Also trying to do the same thing... any one know?


Community Member, 791 Posts

13 November 2008 at 8:57pm


I found a way to do this , but it isn't a particular elegant solution. ;-)

The trick is that in the end , you have to create a GD object Silverstripe can work with. Other than that , it is pretty much straightforward GD work.

The quality can probably be improved, and it eats quite some diskspace and processing power, but it is good enough for what we wanted to achieve.

Look at for the result.

// Read the watermark picture
$watermark = imagecreatefrompng($URL . '/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;

Good luck !