Commits

Bogdan Savluk committed c8a3d2e

watermark method enhancements

  • Participants
  • Parent commits e093480

Comments (0)

Files changed (2)

         return $this;
     }
 
-    public function watermark($path, $x, $y){
+    /**
+     * Places watermark on image
+     * @param string $path path to png image
+     * @param null $x watermark X coordinate, if not set watermark is centered
+     * @param null $y watermark Y coordinate, if not set watermark is centered
+     */
+    public function watermark($path, $x=null, $y=null){
         $this->actions['watermark'] = array
         (
             'path'=>$path, 'x'=>$x, 'y'=>$y,

File drivers/Image_GD_Driver.php

     public function watermark($params)
     {
         $path = $params['path'];
-        $x = $params['x'];
-        $y = $params['y'];
+        $mark = imagecreatefrompng($path);
+        if(isset($params['x'])){
+            $x = $params['x'];
+        } else {
+            $x = (imagesx($this->tmp_image) - imagesx($mark))/2;
+        }
+        if(isset($params['y'])){
+            $y = $params['y'];
+        } else {
+            $y = (imagesy($this->tmp_image) - imagesy($mark))/2;
+        }
         imagealphablending($this->tmp_image, true);
         imagesavealpha($this->tmp_image, true);
-        $mark = imagecreatefrompng($path);
+
         imagecopyresized($this->tmp_image, $mark, $x, $y, 0, 0, imagesx($mark), imagesy($mark), imagesx($mark), imagesy($mark));
         imagedestroy($mark);
         return $this->tmp_image;