Example #1
0
 /**
  * 加水印
  * @param string $text 要添加水印的文字
  * @param int $size 字体大小
  * @param int $opcity 水印透明度
  * @param int $degree 要旋转的角度
  * @param const $position 要添加的位置
  * @param int $x 水平位移
  * @param int $y 垂直位移
  * @return bool 成功返回true,失败返回false
  */
 public function addWaterMark($text, $size, $opacity = 1, $degree = 0, $position = self::Center, $x = 0, $y = 0)
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $black = NewPixelWand('black');
     $none = NewPixelWand('none');
     $textWand = NewMagickWand();
     MagickNewImage($textWand, $width, $height, $none);
     $textDrawWand = NewDrawingWand();
     DrawSetTextEncoding($textDrawWand, 'UTF-8');
     DrawSetFont($textDrawWand, '/Library/Fonts/Hei.ttf');
     DrawSetFontWeight($textDrawWand, 900);
     DrawSetFillColor($textDrawWand, $black);
     DrawSetFontSize($textDrawWand, $size);
     if ($x == 0 && $y == 0) {
         DrawSetGravity($textDrawWand, constant($position));
     }
     DrawSetFillAlpha($textDrawWand, $opacity);
     $degree = intval($degree);
     if ($degree !== 0) {
         DrawRotate($textDrawWand, $degree);
     }
     DrawAnnotation($textDrawWand, $x, $y, $text);
     MagickDrawImage($textWand, $textDrawWand);
     return MagickCompositeImage(self::$resource, $textWand, MW_OverCompositeOp, $x, $y);
 }
Example #2
0
 public function setFont($para = array())
 {
     $textColor = "#000000";
     $textWeight = 120;
     $textSize = 12;
     $textFont = "simsun.ttc";
     $textAlpha = 1;
     $textAlign = 1;
     $textStrokeColor = "#FFFFFF";
     $textStrokeWidth = 1;
     $textStrokeOpacity = 0.2;
     if (count($para) > 1) {
         extract($para, EXTR_OVERWRITE);
     }
     $imgFont = NewDrawingWand();
     $fontColor = $this->getColor($textColor);
     DrawSetTextEncoding($imgFont, "UTF-8");
     DrawSetFont($imgFont, $textFont);
     DrawSetFontWeight($imgFont, $textWeight);
     DrawSetFillColor($imgFont, $fontColor);
     DrawSetFontSize($imgFont, $textSize);
     DrawSetGravity($imgFont, $textAlign);
     DrawSetFillAlpha($imgFont, $textAlpha);
     if ($textStrokeWidth > 0 && $textStrokeOpacity > 0) {
         $strokeColor = $this->getColor($textStrokeColor);
         DrawSetStrokeColor($imgFont, $strokeColor);
         DrawSetStrokeWidth($imgFont, $textStrokeWidth);
         DrawSetStrokeOpacity($imgFont, $textStrokeOpacity);
     }
     if (WandHasException($imgFont)) {
         $this->Error($imgFont);
     }
     $this->destoryWand($fontColor);
     return $imgFont;
 }