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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Watermark in the picture.


6 Posts   782 Views


13 September 2011 at 4:21am Community Member, 4 Posts

Hello, I try to display the watermark on the photo. The code I created a watermark displays, unfortunately the full-page displays. Lose content, etc.
Can you tell me how to properly insert and displays a watermark in the picture? Thank you.
Sorry about my English ...

class Fotka extends DataObject {
static $db = array (
'Popis' => 'Text',
'DatumVlozeni' => 'Date'

static $has_one = array (
'Attachment' => 'Image',
'PodKategorie2' => 'PodKategorie2'

public function Watermark(GD $gd) {
$temp = $this->Attachment();
$watermark = imagecreatefromjpeg(Director::absoluteBaseURL().'mysite/code/water.jpg');
$imageToWatermark = imagecreatefromjpeg(Director::absoluteBaseURL().$temp->Filename);
$imagewatermark_width = imagesx($imageToWatermark);
imagecopymerge($imageToWatermark, $watermark, 39, 45, 0, 0, 400, 400, 40);
$tm = imagejpeg($imageToWatermark);
$GDoutput= new GD($temp->Filename);
// return $tm;
return $GDoutput;

My Template

<% control Fotky %>
<% end_control %>


13 September 2011 at 4:55am Forum Moderator, 1796 Posts


could you try...
return $temp->Filename;
(in Watermark)

<img src="$Watermark"/>
(in the template)



13 September 2011 at 5:25am Community Member, 4 Posts

Thank you for reply, unfortunately the result is the same. I still have a page on the picture.
It's a simple thing to me:

I need to present images to all users. But for registered users will have the opportunity to download images without the watermark. So I thought the simple way is, insert a watermark ...


13 September 2011 at 5:37am Forum Moderator, 1796 Posts

What is "Fotky" is that an instance of Fotka?

what you are doing looks right with the watermark code (I've used that before), but there is quite a bit of missing detail about the "PodKategorie2" page, please post that too.


13 September 2011 at 5:48am Community Member, 4 Posts

Here is

class PodKategorie2 extends Page {

static $has_many = array (
'Fotky' => 'Fotka'

public function getCMSFields()
$f = parent::getCMSFields();

$manager = new ImageDataObjectManager(
$this, // Controller
'Fotky', // Source name
'Fotka', // Source class
'Attachment', // File name on DataObject
null, // Headings
'getCMSFields_forPopup' // Detail fields
// Filter clause
// Sort clause
// Join clause

return $f;

class PodKategorie2_Controller extends Page_Controller {



19 September 2011 at 10:02pm Community Member, 4 Posts

Finally, it has helped create a class WatermarkImage that inherits the image. GetWatermark method, which finally displays a watermark.

class WatermarkImage extends Image {
function getWatermark() {
$watermark = imagecreatefromjpeg(Director::absoluteBaseURL().'mysite/code/watermark.jpg');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg(str_replace('/','\\',Director::baseFolder().'/'.$this->Filename));
$size = getimagesize(str_replace('/','\\',Director::baseFolder().'/'.$this->Filename));
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 40);

in template

<% control Images %>


<% end_control %>