/** * Adds an image watermark to the current image */ public function watermark($file = "", $position = "bottom right", $margin = 10) { try { $wmrk = new Image(); $wmrk->load($file); $wmrk->maxSize(min($this->getWidth(), $this->getHeight()) - $margin * 2); $position = strtolower(Sanitize::toAlnum($position)); $minX = $margin; $minY = $margin; $centerX = ($this->getWidth() - $wmrk->getWidth()) / 2; $centerY = ($this->getHeight() - $wmrk->getHeight()) / 2; $maxX = $this->getWidth() - $wmrk->getWidth() - $margin; $maxY = $this->getHeight() - $wmrk->getHeight() - $margin; $xPos = $maxX; $yPos = $maxY; if (strpos($position, "top") !== false) { $yPos = $minY; } else { if (strpos($position, "middle") !== false) { $yPos = $centerY; } else { if (strpos($position, "bottom") !== false) { $yPos = $maxY; } } } if (strpos($position, "left") !== false) { $xPos = $minX; } else { if (strpos($position, "center") !== false) { $xPos = $centerX; } else { if (strpos($position, "right") !== false) { $xPos = $maxX; } } } return imagecopy($this->img_source, $wmrk->getResource(), $xPos, $yPos, 0, 0, $wmrk->getWidth(), $wmrk->getHeight()); } catch (Exception $e) { } return false; }