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.

Customising the CMS /

put watermark (image stamp) on uploaded image's


2 Posts   2114 Views


Community Member, 14 Posts

27 October 2010 at 9:06pm

Hello i would like to share this with you, there is a lot of tutrials writen on net for watermarking image, but i dident find example for silverstripe:

create ImageDecorator.php (you can named as you want) put in this code

class ImageDecorator extends DataObjectDecorator {

* Put on uploaded images watermark
function onAfterWrite(){

//absolute path to watermark in mycase is watermark located in http://localhost/ak/mysite/code/images/watermark.png
$watermark = imagecreatefrompng(Director::absoluteBaseURL().'mysite/code/images/watermark.png');

//get watermark width
$watermark_width = imagesx($watermark);

//get watermark height
$watermark_height = imagesy($watermark);

//imagecreatetruecolor() returns an image identifier representing a black image of the specified size.
$image = imagecreatetruecolor($watermark_width, $watermark_height);

//imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename.
$image = imagecreatefromjpeg(str_replace('/','\\',Director::baseFolder().'/'.$this->owner->Filename));

//array getimagesize ( string $filename [, array &$imageinfo ] )
$size = getimagesize(str_replace('/','\\',Director::baseFolder().'/'.$this->owner->Filename));

//x-coordinate of destination point.
$dest_x = $size[0] - $watermark_width - 5;

//y-coordinate of destination point.
$dest_y = $size[1] - $watermark_height - 5;

//imagecopymerge — Copy and merge part of an image
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

//imagejpeg — Output image to browser or file , I override uploaded image with the watermarked image

//imagedestroy — Destroy an image

in _config.php insert this code


that's all, it's work fine for me


Community Member, 25 Posts

29 February 2012 at 4:16am

Need help with this - does not work says:

"There was a problem with the upload"

try again.

Any hints why ? 2.4.5