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.

Archive

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

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

Watermark on uploaded image


Reply

4 Posts   2610 Views

Avatar
d_armin

18 May 2007 at 10:05am Community Member, 8 Posts

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

Avatar
Fuzz10

27 August 2008 at 2:16am Community Member, 787 Posts

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 !

Avatar
Brady.Dyer

13 November 2008 at 7:44pm Community Member, 21 Posts

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

Avatar
Fuzz10

13 November 2008 at 8:57pm Community Member, 787 Posts

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 !