コード例 #1
0
ファイル: Image.php プロジェクト: rainner/biscuit-php
 /**
  * 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;
 }
コード例 #2
0
ファイル: Container.php プロジェクト: rainner/biscuit-php
 /**
  * Removes an injected object instance if available
  */
 public function removeObject($name = '')
 {
     $name = Sanitize::toAlnum($name);
     if (!empty($name) && array_key_exists($name, $this->_objects)) {
         unset($this->_objects[$name]);
     }
 }