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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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   1154 Views

Avatar
CHD

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: http://ace.clickheredigital.co.uk/roofing-photo-gallery/
and my watermark is stored here: http://ace.clickheredigital.co.uk/themes/Ace/images/watermark.png

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.

Avatar
CHD

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