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:

General Questions /

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

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

Watermark in the picture.

Go to End

6 Posts   1195 Views


Community Member, 4 Posts

13 September 2011 at 4:21am

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


Forum Moderator, 1899 Posts

13 September 2011 at 4:55am


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

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



Community Member, 4 Posts

13 September 2011 at 5:25am

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


Forum Moderator, 1899 Posts

13 September 2011 at 5:37am

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.


Community Member, 4 Posts

13 September 2011 at 5:48am

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 {


Community Member, 4 Posts

19 September 2011 at 10:02pm

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