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

Image_Gallery and watermark

Go to End

2 Posts   1038 Views


Community Member, 219 Posts

2 October 2010 at 7:51am

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.


Community Member, 219 Posts

4 October 2010 at 11:37pm

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??