Basically, I have 2 php script. 1 of the php scripts is to display and the other 1 is the watermark function.
I use this PHP to display the image with watermark:
You can add and customize your output pictures with simple php codes like this that working with TopiLib: (You can add both image and text watermark, too)
createFromPNG($_GET['image'], true);
$img = new \TopiLib\TopiImage('watermark.png', 'transparent png');
$img->startX = 100; //your custom start X position
$img->startY = 100; //your custom start Y position
$panel->addImage($img);
$panel->render(); ?>