コード例 #1
0
ファイル: GD.php プロジェクト: Abuamany/concerto-platform
 public function watermark($text, $font, $size, $color, $transparency, $place)
 {
     if (strlen($text) == 0) {
         return;
     }
     if (is_array($color)) {
         list($red, $green, $blue) = $color;
     } else {
         list($red, $green, $blue) = PGRThumb_Utils::html2rgb($color);
     }
     $x = 0;
     $y = 0;
     $textcord = imagettfbbox($size, 0, $font, $text);
     $textWidth = $textcord[4] - $textcord[6];
     $textHeight = $textcord[1] - $textcord[7];
     $textCenterX = round($this->_width / 2 - $textWidth / 2);
     $textCenterY = round($this->_height / 2 + $textHeight / 3);
     $padding = 2;
     switch ($place) {
         case 'LT':
             $y = $padding + $textHeight;
             $x = $padding;
             break;
         case 'CT':
             $y = $padding + $textHeight;
             $x = $textCenterX;
             break;
         case 'RT':
             $y = $padding + $textHeight;
             $x = $this->_width - $textWidth - $padding;
             break;
         case 'LC':
             $y = $textCenterY;
             $x = $padding;
             break;
         case 'CC':
             $y = $textCenterY;
             $x = $textCenterX;
             break;
         case 'RC':
             $y = $textCenterY;
             $x = $this->_width - $textWidth - $padding;
             break;
         case 'LB':
             $y = $this->_height - $padding;
             $x = $padding;
             break;
         case 'CB':
             $y = $this->_height - $padding;
             $x = $textCenterX;
             break;
         case 'RB':
             $y = $this->_height - $padding;
             $x = $this->_width - $textWidth - $padding;
             break;
     }
     $color = imagecolorallocatealpha($this->_processedImage, $red, $green, $blue, $transparency);
     imagettftext($this->_processedImage, $size, 0, $x, $y, $color, $font, $text);
 }
コード例 #2
0
ファイル: ImageMagick.php プロジェクト: moahmed/ezcms
 public function watermark($text, $font, $size, $color, $transparency, $place)
 {
     if (is_array($color)) {
         list($red, $green, $blue) = $color;
     } else {
         list($red, $green, $blue) = PGRThumb_Utils::html2rgb($color);
     }
     switch ($place) {
         case 'LT':
             $place = "NorthWest";
             break;
         case 'CT':
             $place = "North";
             break;
         case 'RT':
             $place = "NorthEast";
             break;
         case 'LC':
             $place = "West";
             break;
         case 'CC':
             $place = "Center";
             break;
         case 'RC':
             $place = "East";
             break;
         case 'LB':
             $place = "SouthWest";
             break;
         case 'CB':
             $place = "South";
             break;
         case 'RB':
             $place = "SouthEast";
             break;
     }
     $this->_commands[] = '-font "' . $font . '"';
     $this->_commands[] = '-draw \'text gravity ' . $place . ' color "rgb(' . $red . ',' . $green . ',' . $blue . ')" "' . $text . '"\'';
 }