17452 Posts in 4473 Topics by 1971 members
|Go to End|
18 May 2007 at 10:05am
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
Where i need to insert this snippet, to add the watermark to the uploaded image
from the cms.
27 August 2008 at 2:16am
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 !
13 November 2008 at 7:44pm
Also trying to do the same thing... any one know?
13 November 2008 at 8:57pm
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 - $watermark_width - 5;
$dest_y = $size - $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");
Good luck !
|Go to Top|