Exemplo n.º 1
0
 /**
  * 获取文字的描绘对象
  * @param string $font 字体名称或字体路径
  * @param integer $size 字体大小
  * @param string | ImagickPixel $color 字颜色
  * @param float $opacity 文字的透明度,取值范围0(全透明)-1(不透明)
  * @param string | ImagickPixel $underColor 字的背景颜色
  * @return ImagickDraw | false
  */
 public function getDrawForText($font = null, $size = 8, $color = 'transparent', $opacity = 0.58, $underColor = null)
 {
     $draw = new ImagickDraw();
     // $draw->setGravity(Imagick::GRAVITY_CENTER);
     // 特别注意这里了,如果这里设置了文字水印的位置的话,那么在其写入别到文件时就会起作用,且其他设置的坐标都没有用
     if ($font !== null) {
         if (is_file($font)) {
             $draw->setfont($font);
         } else {
             $this->_error = '字体文件不存在';
             return false;
         }
     }
     $draw->setfontsize($size);
     $draw->setFillColor($color);
     $draw->setfillopacity($opacity);
     // 貌似和这个是一样的: $draw->setFillAlpha(0.5);
     if ($underColor !== null) {
         $draw->settextundercolor($underColor);
     }
     // $draw->settextalignment(2); //文字对齐方式,2为居中
     return $draw;
 }
Exemplo n.º 2
0
 /**
  * Watermars the image with the viewer's IP
  * @return boolean
  */
 public function watermark()
 {
     $text = $_SERVER['REMOTE_ADDR'];
     $font = $_SERVER['DOCUMENT_ROOT'] . '/pixel.ttf';
     $image = $this->getImagick();
     $width = $image->getimagewidth();
     $watermark = new Imagick();
     $watermark->newImage(1000, 1000, new ImagickPixel('none'));
     $draw = new ImagickDraw();
     $draw->setFont($font);
     $draw->setfontsize(30);
     $draw->setFillColor('gray');
     $draw->setFillOpacity(0.3);
     $watermark->annotateimage($draw, 100, 200, -45, $text);
     $watermark->annotateimage($draw, 550, 550, 45, $text);
     $this->iMagick = $image->textureimage($watermark);
     return true;
 }
Exemplo n.º 3
0
function psychedelicFontGif($name = 'Danack')
{
    set_time_limit(3000);
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $maxFrames = 11;
    $scale = 0.25;
    for ($frame = 0; $frame < $maxFrames; $frame++) {
        $draw = new \ImagickDraw();
        $draw->setStrokeOpacity(1);
        $draw->setFont("../fonts/CANDY.TTF");
        $draw->setfontsize(150 * $scale);
        for ($strokeWidth = 25; $strokeWidth > 0; $strokeWidth--) {
            $hue = intval(fmod($frame * 360 / $maxFrames + 170 + $strokeWidth * 360 / 25, 360));
            $color = "hsl({$hue}, 255, 128)";
            $draw->setStrokeColor($color);
            $draw->setFillColor($color);
            $draw->setStrokeWidth($strokeWidth * 3 * $scale);
            $draw->annotation(60 * $scale, 165 * $scale, $name);
        }
        $draw->setStrokeColor('none');
        $draw->setFillColor('black');
        $draw->setStrokeWidth(0);
        $draw->annotation(60 * $scale, 165 * $scale, $name);
        //Create an image object which the draw commands can be rendered into
        $imagick = new \Imagick();
        $imagick->newImage(650 * $scale, 230 * $scale, "#eee");
        $imagick->setImageFormat("png");
        //Render the draw commands in the ImagickDraw object
        //into the image.
        $imagick->drawImage($draw);
        $imagick->setImageDelay(5);
        $aniGif->addImage($imagick);
        $imagick->destroy();
    }
    $aniGif->setImageIterations(0);
    //loop forever
    $aniGif->deconstructImages();
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}
Exemplo n.º 4
0
 /**
  * 
  * 文字水印
  * @param unknown_type $data
  */
 public function addWaterText($data)
 {
     $draw = new ImagickDraw();
     $this->ImagickPixel = new ImagickPixel();
     $draw->clear();
     $draw->setfont($data['font']);
     $draw->setfontsize($data['size']);
     $this->ImagickPixel->setcolor($data['color']);
     $draw->setfillcolor($data['color']);
     $draw->setfillalpha($data['alpha']);
     $draw->settextalignment(imagick::GRAVITY_NORTHWEST);
     //左对齐
     $draw->annotation($data['pos_x'], $data['pos_y'], $data['literal']);
     $this->srcImg_source->drawimage($draw);
     $draw->destroy();
     return $this->srcImg_source;
 }