Good morning,
I want to use the panel hooks to add a watermark to every uploaded or replaced image.
The hooks are being executed as expected.
I tried to implement this php manual example using the gd library. And it seems like I’m unable to save the created image.
Can i somehow use f::write()
to save or overwrite the uploaded image?
Kudos
You have to add a destination:
kirby()->hook('panel.file.upload', function($file) {
$stamp = imagecreatefrompng(kirby()->roots()->assets(). '/images/stamp.png');
$path = $file->url();
$im = imagecreatefromjpeg($path);
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
imagepng($im, $file->page()->root() . '/' . $file->filename());
imagedestroy($im);
});
Thanks a lot. You were right, adding the destination solved it!