Example #1
0
 public function watermark(ImageManipulator $image, $watermarkImage, $isLeft, $isTop, $marginX, $marginY)
 {
     // Load the stamp and the photo to apply the watermark to
     $stamp = $this->getGDImage($watermarkImage);
     $im = $this->getGDImage($image->getImagePath());
     // Set the margins for the stamp and get the height/width of the stamp image
     $sx = imagesx($stamp);
     $sy = imagesy($stamp);
     // center?
     if (is_null($marginX) && is_null($marginY)) {
         $left = (imagesx($im) - $sx) / 2;
         $top = (imagesy($im) - $sy) / 2;
     } else {
         $left = $isLeft ? $marginX : imagesx($im) - $sx - $marginX;
         $top = $isTop ? $marginY : imagesy($im) - $sy - $marginY;
     }
     // Copy the stamp image onto our photo using the margin offsets and the photo
     // width to calculate positioning of the stamp.
     imagecopy($im, $stamp, $left, $top, 0, 0, $sx, $sy);
     // Output and free memory
     $this->save($image->getType(), $im, $image->getImagePath(), $image->getQuality());
     imagedestroy($im);
 }