Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Watermark on uploaded image

Our old forums are still available as a read-only archive.

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

Page: 1
Go to End
Author Topic: 2611 Views
  • d_armin
    Avatar
    Community Member
    8 Posts

    Watermark on uploaded image Link to this post

    Hi,
    i want to add a watermark to a uploaded image. Any idea?
    I have a class to watermark the image, but i can't figure it out where
    to insert the watermark method.
    it looks like
    $thumb=new Thumbnail($filename);
    $thumb->img_watermark='watermark.png';
    $thumb->img_watermark_Valing='BOTTOM';
    $thumb->img_watermark_Haling='RIGHT';
    $thumb->process();
    Where i need to insert this snippet, to add the watermark to the uploaded image
    from the cms.

    Thanks

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Watermark on uploaded image Link to this post

    Old message, but it resembles my question.

    I'd like to manipulate uploaded images myself using GD (I need to watermark them). But since the Silverstripe images are wrapped in the (silverstripe) GD class, I can't figure out where to "hook" my watermark code.

    Can anyone give me some pointers ? Thanks !

  • Brady.Dyer
    Avatar
    Community Member
    21 Posts

    Re: Watermark on uploaded image Link to this post

    Also trying to do the same thing... any one know?

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Watermark on uploaded image Link to this post

    Yeah.

    I found a way to do this , but it isn't a particular elegant solution. ;-)

    The trick is that in the end , you have to create a GD object Silverstripe can work with. Other than that , it is pretty much straightforward GD work.

    The quality can probably be improved, and it eats quite some diskspace and processing power, but it is good enough for what we wanted to achieve.

    Look at http://www.fahrenheitstore.nl for the result.

    // Read the watermark picture
    $watermark = imagecreatefrompng($URL . '/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;

    Good luck !

    2611 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.