当前位置: 首页>>代码示例>>PHP>>正文


PHP ImagickDraw::setFillOpacity方法代码示例

本文整理汇总了PHP中ImagickDraw::setFillOpacity方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagickDraw::setFillOpacity方法的具体用法?PHP ImagickDraw::setFillOpacity怎么用?PHP ImagickDraw::setFillOpacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ImagickDraw的用法示例。


在下文中一共展示了ImagickDraw::setFillOpacity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: perform

 /**
  * Draws an ellipse on the handle
  *
  * @param ImageMagick-object $handle The handle on which the ellipse is drawn
  * @param Zend_Image_Action_DrawEllipse $ellipseObject The object that with all info
  */
 public function perform(Zend_Image_Adapter_ImageMagick $adapter, Zend_Image_Action_DrawEllipse $ellipseObject)
 {
     $draw = new ImagickDraw();
     $strokeColor = (string) $ellipseObject->getStrokeColor();
     $strokeAlpha = $ellipseObject->getStrokeAlpha() * 0.01;
     $draw->setStrokeColor($strokeColor);
     $draw->setStrokeOpacity($strokeAlpha);
     $draw->setStrokeWidth($ellipseObject->getStrokeWidth());
     $strokeDashArray = $ellipseObject->getStrokeDashPattern();
     if (count($strokeDashArray) > 0) {
         $draw->setStrokeDashArray($strokeDashArray);
     }
     $draw->setStrokeDashOffset($ellipseObject->getStrokeDashOffset());
     if ($ellipseObject->filled()) {
         $fillColor = (string) $ellipseObject->getFillColor();
         $draw->setFillColor($fillColor);
         $draw->setFillOpacity($ellipseObject->getFillAlpha() * 0.01);
     } else {
         $draw->setFillOpacity(0);
     }
     $width = $ellipseObject->getWidth();
     $height = $ellipseObject->getHeight();
     $x = $ellipseObject->getLocation()->getX();
     $y = $ellipseObject->getLocation()->getY();
     $draw->ellipse($x, $y, $width / 2, $height / 2, 0, 360);
     $adapter->getHandle()->drawImage($draw);
 }
开发者ID:BGCX262,项目名称:zym-svn-to-git,代码行数:33,代码来源:DrawEllipse.php

示例2: perform

    /**
     * Draws a polygon on the handle
     *
     * @param ImageMagick-object $handle The handle on which the polygon is drawn
     * @param Zend_Image_Action_DrawPolygon $polygon The object that with all info
     */
    public function perform($handle, Zend_Image_Action_DrawPolygon $polygon) { // As of ZF2.0 / PHP5.3, this can be made static.
        
        $points = $this->_parsePoints($polygon->getPoints());

        if ($polygon->isClosed()){
            //add first point at the end to close
            $points[count($points)] = $points[0];
        }

        $draw = new ImagickDraw();

        $draw->setStrokeColor('#' . $polygon->getStrokeColor()->getHex());

        $draw->setStrokeOpacity($polygon->getStrokeAlpha()/100);
        $draw->setStrokeWidth($polygon->getStrokeWidth());

        $strokeDashArray = $polygon->getStrokeDashPattern();
        if (count($strokeDashArray) > 0){
            $draw->setStrokeDashArray($strokeDashArray);
        }
        $draw->setStrokeDashOffset($polygon->getStrokeDashOffset());

        if($polygon->isFilled()) {
            $fillColor = $polygon->getFillColor();
            $draw->setFillColor('#' . $fillColor->getHex());
            $draw->polygon($points);

        } else {
            //Use transparent fill to render unfilled
            $draw->setFillOpacity(0);
            $draw->polyline($points);
        }

        $handle->getHandle()->drawImage($draw);
    }
开发者ID:BGCX262,项目名称:zym-svn-to-git,代码行数:41,代码来源:DrawPolygon.php

示例3: printText

 public function printText($canvas, $size, $angle, $x, $y, $color, $fontfile, $text, $opacity = 100)
 {
     $draw = new ImagickDraw();
     $draw->setFillColor(self::rgb($color));
     $draw->setFontSize($size * $this->fontSizeScale);
     $draw->setFont($fontfile);
     $draw->setFillOpacity($opacity / 100);
     $canvas->annotateImage($draw, $x, $y, $angle, $text);
 }
开发者ID:neilcrookes,项目名称:Ximi,代码行数:9,代码来源:ximi_image_imagick.php

示例4: draw

 public function draw(OsuSignature $signature)
 {
     if (empty($this->hexColour)) {
         $this->hexColour = $signature->getHexColour();
     }
     $composite = new Imagick();
     $composite->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
     // Background
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel("#555555"));
     $draw->rectangle(0, 0, $this->getWidth(), $this->getHeight());
     $composite->drawImage($draw);
     // Main bar
     $level = $signature->getUser()['level'];
     $xp = $level - floor($level);
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel($this->hexColour));
     $draw->rectangle(0, 0, $this->getWidth() * $xp, $this->getHeight());
     $composite->drawImage($draw);
     // Bar end glow
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel('#ffffff'));
     $draw->setFillOpacity(0.35);
     $draw->rectangle($this->getWidth() * $xp - $this->getHeight(), 0, $this->getWidth() * $xp, $this->getHeight());
     $composite->drawImage($draw);
     // Text draw & metrics
     $textDraw = new ImagickDraw();
     $textDraw->setFillColor(new ImagickPixel('#555555'));
     $textDraw->setFontSize(12);
     $textDraw->setFont(ComponentLabel::FONT_DIRECTORY . ComponentLabel::FONT_REGULAR);
     $textDraw->setGravity(Imagick::GRAVITY_NORTHWEST);
     $metrics = $composite->queryFontMetrics($textDraw, 'lv' . floor($level));
     // Text white bg
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel('#ffffff'));
     $draw->rectangle(($this->getWidth() - $metrics['textWidth']) / 2 - 2, 0, ($this->getWidth() + $metrics['textWidth']) / 2 + 1, $this->getHeight());
     $composite->drawImage($draw);
     // Rounding
     $roundMask = new Imagick();
     $roundMask->newPseudoImage($this->getWidth(), $this->getHeight(), "canvas:transparent");
     $draw = new ImagickDraw();
     $draw->setFillColor(new ImagickPixel("black"));
     $draw->roundRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $this->rounding, $this->rounding);
     $roundMask->drawImage($draw);
     $roundMask->setImageFormat('png');
     $composite->compositeImage($roundMask, Imagick::COMPOSITE_DSTIN, 0, 0, Imagick::CHANNEL_ALPHA);
     $signature->getCanvas()->compositeImage($composite, Imagick::COMPOSITE_DEFAULT, $this->x, $this->y);
     // Level text
     $signature->getCanvas()->annotateImage($textDraw, $this->x + ($this->getWidth() - $metrics['textWidth']) / 2, $this->y + ($this->getHeight() - $metrics['textHeight']) / 2 - 2, 0, 'lv' . floor($level));
 }
开发者ID:BTCTaras,项目名称:osusig,代码行数:50,代码来源:ComponentXPBar.php

示例5: draw

 public function draw($image)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeWidth($this->borderSize);
     if (null !== $this->fillColor) {
         $fillColor = new \ImagickPixel($this->fillColor->getHexString());
         $draw->setFillColor($fillColor);
     } else {
         $draw->setFillOpacity(0);
     }
     if (null !== $this->borderColor) {
         $borderColor = new \ImagickPixel($this->borderColor->getHexString());
         $draw->setStrokeColor($borderColor);
     } else {
         $draw->setStrokeOpacity(0);
     }
     $draw->polygon($this->points());
     $image->getCore()->drawImage($draw);
     return $image;
 }
开发者ID:kosinix,项目名称:grafika,代码行数:20,代码来源:Polygon.php

示例6: draw

 public function draw($image)
 {
     $draw = new \ImagickDraw();
     $draw->setStrokeWidth($this->borderSize);
     if (null !== $this->fillColor) {
         $fillColor = new \ImagickPixel($this->fillColor->getHexString());
         $draw->setFillColor($fillColor);
     } else {
         $draw->setFillOpacity(0);
     }
     if (null !== $this->borderColor) {
         $borderColor = new \ImagickPixel($this->borderColor->getHexString());
         $draw->setStrokeColor($borderColor);
     } else {
         $draw->setStrokeOpacity(0);
     }
     $x1 = $this->pos[0];
     $x2 = $x1 + $this->getWidth();
     $y1 = $this->pos[1];
     $y2 = $y1 + $this->getHeight();
     $draw->rectangle($x1, $y1, $x2, $y2);
     $image->getCore()->drawImage($draw);
     return $image;
 }
开发者ID:kosinix,项目名称:grafika,代码行数:24,代码来源:Rectangle.php

示例7: text

 /**
  * Execute a text
  *
  * @param string $text
  * @param int    $offsetX
  * @param int    $offsetY
  * @param float  $opacity
  * @param int    $color
  * @param int    $size
  * @param string $font_file
  *
  * @return static
  */
 public function text($text, $offsetX = 0, $offsetY = 0, $opacity = 1.0, $color = 0x0, $size = 12, $font_file = null)
 {
     $draw = new \ImagickDraw();
     $textColor = sprintf('rgb(%u,%u,%u)', $color >> 16 & 0xff, $color >> 8 & 0xff, $color & 0xff);
     $draw->setFillColor(new \ImagickPixel($textColor));
     if ($font_file) {
         $draw->setFont($this->alias->resolve($font_file));
     }
     $draw->setFontSize($size);
     $draw->setFillOpacity($opacity);
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $this->_image->annotateImage($draw, $offsetX, $offsetY, 0, $text);
     $draw->destroy();
     return $this;
 }
开发者ID:manaphp,项目名称:manaphp,代码行数:28,代码来源:Imagick.php

示例8: _watermark

 /**
  * @param array $options
  *     'watermark' => waImage|string $watermark
  *     'opacity' => float|int 0..1
  *     'align' => self::ALIGN_* const
  *     'font_file' => null|string If null - will be used some default font. Note: use when watermark option is text
  *     'font_size' => float Size of font. Note: use when watermark option is text
  *     'font_color' => string Hex-formatted of color (without #). Note: use when watermark option is text
  *     'text_orientation' => self::ORIENTATION_* const. Note: use when watermark option is text
  * @return mixed
  */
 protected function _watermark($options)
 {
     $opacity = 0.5;
     $watermark = false;
     $align = self::ALIGN_BOTTOM_RIGHT;
     $font_file = null;
     $font_size = 12;
     $font_color = '888888';
     $text_orientation = self::ORIENTATION_HORIZONTAL;
     extract($options, EXTR_IF_EXISTS);
     $opacity = min(max($opacity, 0), 1);
     /**
      * @var waImage $watermark
      */
     if ($watermark instanceof waImage) {
         $width = ifset($options['width'], $watermark->width);
         $height = ifset($options['height'], $watermark->height);
         $offset = $this->calcWatermarkOffset($width, $height, $align);
         $iwatermark = new Imagick($watermark->file);
         if ($width != $watermark->width || $height != $watermark->height) {
             $iwatermark->resizeImage($width, $height, Imagick::FILTER_CUBIC, 0.5);
         }
         if (method_exists($iwatermark, 'setImageAlphaChannel')) {
             try {
                 $iwatermark->setImageAlphaChannel(Imagick::ALPHACHANNEL_ACTIVATE);
             } catch (Exception $e) {
             }
         }
         $iwatermark->evaluateImage(Imagick::EVALUATE_MULTIPLY, $opacity, Imagick::CHANNEL_ALPHA);
         $this->im->compositeImage($iwatermark, Imagick::COMPOSITE_DISSOLVE, $offset[0], $offset[1]);
         $iwatermark->clear();
         $iwatermark->destroy();
     } else {
         $text = (string) $watermark;
         if (!$text) {
             return;
         }
         $font_size = 24 * $font_size / 18;
         // 24px = 18pt
         $font_color = new ImagickPixel('#' . $font_color);
         $watermark = new ImagickDraw();
         $watermark->setFillColor($font_color);
         $watermark->setFillOpacity($opacity);
         if ($font_file && file_exists($font_file)) {
             $watermark->setFont($font_file);
         }
         $watermark->setFontSize($font_size);
         // Throws ImagickException on error
         $metrics = $this->im->queryFontMetrics($watermark, $text);
         $width = $metrics['textWidth'];
         $height = $metrics['textHeight'];
         if ($text_orientation == self::ORIENTATION_VERTICAL) {
             list($width, $height) = array($height, $width);
         }
         $margin = round($font_size * 0.21);
         list($offset, $rotation) = $this->calcWatermarkTextOffset($width, $height, $align, $text_orientation, ifset($options['rotation']), $margin);
         $this->im->annotateImage($watermark, $offset[0], $offset[1], $rotation, $text);
         $watermark->clear();
         $watermark->destroy();
     }
 }
开发者ID:Lazary,项目名称:webasyst,代码行数:72,代码来源:waImageImagick.class.php

示例9: ImagickDraw

    /*** Set memory limit to 8 MB ***/
    $im->setResourceLimit(Imagick::RESOURCETYPE_MEMORY, 8);
    /*** read the image into the object ***/
    $im->readImage($image);
    /* Create a drawing object and set the font size */
    $draw = new ImagickDraw();
    /*** set the font ***/
    $draw->setFont("/Library/Fonts/Impact.ttf");
    /*** set the font size ***/
    $draw->setFontSize(36);
    /*** add some transparency ***/
    /*** set gravity to the center ***/
    $draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
    /*** overlay the text on the image ***/
    $draw->setFillColor('white');
    $draw->setFillOpacity(0.6);
    $im->annotateImage($draw, 0, 0, 0, "voices4earth.org");
    /**** set to png ***/
    $im->setImageFormat("png");
    /*** write image to disk ***/
    $im->writeImage('/Library/WebServer/Documents/Sites/VEJ/temp/watermark_overlay.png');
    echo 'Image Created';
} catch (Exception $e) {
    echo $e->getMessage();
}
///Library/WebServer/Documents/Sites/VEJ/temp/dropshadow.png
?>


</section>
开发者ID:richs5812,项目名称:VEJ_website,代码行数:30,代码来源:imagick_text_overlay.php

示例10: addWatermarkTextMosaic

 public function addWatermarkTextMosaic($text = "Copyright", $font = "Courier", $size = 20, $color = "grey70", $maskColor = "grey30", $position = \Imagick::GRAVITY_SOUTHEAST)
 {
     $watermark = new \Imagick();
     $draw = new \ImagickDraw();
     $watermark->newImage(140, 80, new \ImagickPixel('none'));
     $draw->setFont($font);
     $draw->setFillColor('grey');
     $draw->setFillOpacity(0.4);
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $watermark->annotateImage($draw, 10, 10, 0, $text);
     $draw->setGravity(\Imagick::GRAVITY_SOUTHEAST);
     $watermark->annotateImage($draw, 5, 15, 0, $text);
     for ($w = 0; $w < $this->getImage()->getImageWidth(); $w += 140) {
         for ($h = 0; $h < $this->getImage()->getImageHeight(); $h += 80) {
             $this->getImage()->compositeImage($watermark, \Imagick::COMPOSITE_OVER, $w, $h);
         }
     }
 }
开发者ID:deltaphp,项目名称:image,代码行数:18,代码来源:Imagick.php

示例11: draw_text

function draw_text($poster, $y, $font_size, $text)
{
    $draw = new ImagickDraw();
    $draw->setFont(is_ascii($text) ? '../font/bernhc.ttf' : '../font/ヒラギノ角ゴ StdN W8.otf');
    $draw->setFillOpacity(0.6);
    $draw->setFontSize($font_size);
    $draw->annotation(0, $font_size, $text);
    $fm = $poster->queryFontMetrics($draw, $text, false);
    $text_im = trample_text_layer($draw, $fm['textWidth'], $fm['textHeight']);
    if ($text_im->getImageWidth() > 160) {
        $text_im->scaleImage(160, $text_im->getImageHeight());
    }
    $poster->compositeImage($text_im, imagick::COMPOSITE_OVER, ($poster->getImageWidth() - $text_im->getImageWidth()) / 2, $y);
}
开发者ID:Adios,项目名称:Wanted,代码行数:14,代码来源:make.php

示例12: previewWithCropAction

 public function previewWithCropAction()
 {
     $previewWidth = 390;
     $previewHeight = 184;
     $fileRow = Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model')->getRow($this->_getParam('uploadId'));
     if (!$fileRow) {
         throw new Kwf_Exception("Can't find upload");
     }
     if ($fileRow->getHashKey() != $this->_getParam('hashKey')) {
         throw new Kwf_Exception_AccessDenied();
     }
     //Scale dimensions
     $dimensions = array($previewWidth, $previewHeight, 'cover' => false);
     $cache = Kwf_Assets_Cache::getInstance();
     $cacheId = 'previewLarge_' . $fileRow->id;
     if (!($output = $cache->load($cacheId))) {
         $output = array();
         $output['contents'] = Kwf_Media_Image::scale($fileRow->getFileSource(), $dimensions, $fileRow->id);
         $output['mimeType'] = $fileRow->mime_type;
         $cache->save($output, $cacheId);
     }
     $cropX = $this->_getParam('cropX');
     $cropY = $this->_getParam('cropY');
     $cropWidth = $this->_getParam('cropWidth');
     $cropHeight = $this->_getParam('cropHeight');
     $imageOriginal = new Imagick($fileRow->getFileSource());
     if ($this->_getParam('cropX') == null || $this->_getParam('cropY') == null || $this->_getParam('cropWidth') == null || $this->_getParam('cropHeight') == null) {
         //calculate default selection
         $dimension = $this->_getParam('dimension');
         if (!$dimension) {
             Kwf_Media_Output::output($output);
         }
         $dimension = array('width' => $this->_getParam('dimension_width') ? $this->_getParam('dimension_width') : 0, 'height' => $this->_getParam('dimension_height') ? $this->_getParam('dimension_height') : 0, 'cover' => $this->_getParam('dimension_cover') ? $this->_getParam('dimension_cover') : false);
         if ($dimension['width'] == Kwf_Form_Field_Image_UploadField::USER_SELECT) {
             $dimension['width'] = $this->_getParam('width');
         }
         if ($dimension['height'] == Kwf_Form_Field_Image_UploadField::USER_SELECT) {
             $dimension['height'] = $this->_getParam('height');
         }
         if (!$dimension['cover']) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['width'] == Kwf_Form_Field_Image_UploadField::CONTENT_WIDTH) {
             Kwf_Media_Output::output($output);
         }
         if ($dimension['height'] == 0 || $dimension['width'] == 0) {
             Kwf_Media_Output::output($output);
         }
         $cropX = 0;
         $cropY = 0;
         $cropHeight = $imageOriginal->getImageHeight();
         $cropWidth = $imageOriginal->getImageWidth();
         if ($imageOriginal->getImageHeight() / $dimension['height'] > $imageOriginal->getImageWidth() / $dimension['width']) {
             // orientate on width
             $cropHeight = $dimension['height'] * $imageOriginal->getImageWidth() / $dimension['width'];
             $cropY = ($imageOriginal->getImageHeight() - $cropHeight) / 2;
         } else {
             // orientate on height
             $cropWidth = $dimension['width'] * $imageOriginal->getImageHeight() / $dimension['height'];
             $cropX = ($imageOriginal->getImageWidth() - $cropWidth) / 2;
         }
     }
     // Calculate values relative to preview image
     $image = new Imagick();
     $image->readImageBlob($output['contents']);
     $previewFactor = 1;
     if ($image->getImageWidth() == $previewWidth) {
         $previewFactor = $image->getImageWidth() / $imageOriginal->getImageWidth();
     } else {
         if ($image->getImageHeight() == $previewHeight) {
             $previewFactor = $image->getImageHeight() / $imageOriginal->getImageHeight();
         }
     }
     $cropX = floor($cropX * $previewFactor);
     $cropY = floor($cropY * $previewFactor);
     $cropWidth = floor($cropWidth * $previewFactor);
     $cropHeight = floor($cropHeight * $previewFactor);
     $draw = new ImagickDraw();
     if ($this->_isLightImage($output)) {
         $draw->setFillColor('black');
     } else {
         $draw->setFillColor('white');
     }
     $draw->setFillOpacity(0.3);
     // if cropX == 0 or cropY == 0 no rectangle should be drawn, because it
     // can't be 0 wide on topmost and leftmost position so it will result in
     // a 1px line which is wrong
     //Top region
     if ($cropY > 0) {
         $draw->rectangle(0, 0, $image->getImageWidth(), $cropY);
     }
     //Left region
     if ($cropX > 0) {
         if ($cropY > 0) {
             $draw->rectangle(0, $cropY + 1, $cropX, $cropY + $cropHeight - 1);
         } else {
             $draw->rectangle(0, $cropY, $cropX, $cropY + $cropHeight - 1);
         }
     }
     //Right region
//.........这里部分代码省略.........
开发者ID:koala-framework,项目名称:koala-framework,代码行数:101,代码来源:UploadController.php

示例13: annotate

 /**
  * 添加文字注解,可用于文字水印
  *
  * @param string $txt 必须为utf8编码,文档格式utf-8格式即可
  * @param float $opacity 设置不透明度
  * @param constant $gravity 设置文字摆放位置,GRAVITY_NorthWest,GRAVITY_North,GRAVITY_NorthEast,GRAVITY_West,
  *                 GRAVITY_Center,GRAVITY_East,GRAVITY_SouthWest,GRAVITY_South,GRAVITY_SouthEast,SAE_Static
  * @param array $font 字体数组可以设置如下属性:
  *  <pre>
  *     name,常量,字体名称,如果需要添加中文注解,请使用中文字体,否则中文会显示乱码。
  *       支持的字体:FONT_SimSun(宋体,默认)、FONT_SimKai(楷体)、FONT_SimHei(正黑)、FONT_MicroHei(微米黑)、FONT_Arial
  *     weight,字体宽度,int
  *     size,字体大小,int
  *     color,字体颜色,例如:"blue", "#0000ff", "rgb(0,0,255)"等,默认为"black";
  *  </pre>
  *
  * @return bool
  * @author Sauwe
  */
 public function annotate($txt, $opacity = 0.5, $gravity = SAE_Static, $font = array("name" => FONT_SimSun, "size" => 15, "weight" => 300, "color" => "black"))
 {
     if ($this->notValid()) {
         return false;
     }
     $opacity = floatval($opacity);
     $fontfamily = FONT_SimSun;
     if (isset($font["name"])) {
         $fontfamily = $font["name"];
     }
     $fontsize = 15;
     if (isset($font["size"])) {
         $fontsize = $font["size"];
     }
     $fontweight = 300;
     if (isset($font["weight"])) {
         $fontweight = $font["weight"];
     }
     $fontcolor = "black";
     if (isset($font["color"])) {
         $fontcolor = $font["color"];
     }
     try {
         $im = new Imagick();
         $im->readImageBlob($this->_img_data);
         $id = new ImagickDraw();
         $id->setFont($fontfamily);
         //这里是一个实际上的字体路径
         $id->setFontSize($fontsize);
         $id->setFontWeight($fontweight);
         $id->setFillColor(new ImagickPixel($fontcolor));
         $id->setGravity($gravity);
         $id->setFillOpacity($opacity);
         if ($im->annotateImage($id, 0, 0, 0, $txt)) {
             $this->_img_data = $im->getImageBlob();
             return true;
         }
         return false;
     } catch (Exception $e) {
         $this->_errno = SAE_ErrUnknown;
         $this->_errmsg = $e->getMessage();
         return false;
     }
 }
开发者ID:xuyintao,项目名称:thindev,代码行数:63,代码来源:Imagick.class.php

示例14: watermark

 /**
  * 添加水印
  */
 public function watermark()
 {
     if (!is_file($this->watermarkFile)) {
         throw new Exception('Watermark file not found');
     }
     $watermark = new Imagick($this->watermarkFile);
     if ($watermark->getImageWidth() > $this->getWidth()) {
         throw new Exception('Watermark file too width');
     }
     if ($watermark->getImageHeight() > $this->getHeight()) {
         throw new Exception('Watermark file too height');
     }
     $dw = new ImagickDraw();
     $dw->setFillOpacity(0.8);
     $dw->setGravity($this->watermarkPosition);
     $dw->composite($watermark->getImageCompose(), 0, 0, 0, 0, $watermark);
     if ($this->getFrames() > 1) {
         foreach ($this->im as $frame) {
             $this->im->drawImage($dw);
         }
         $this->im->writeImages($this->targetName, TRUE);
     } else {
         $this->im->drawImage($dw);
         $this->im->writeImage($this->targetName);
     }
 }
开发者ID:timy-life,项目名称:segments,代码行数:29,代码来源:ImageMagick.php

示例15: watermarkText

 public function watermarkText($overlayText, $position, $param = array('rotation' => 0, 'opacity' => 50, 'color' => 'FFF', 'size' => null))
 {
     $imagick = new Imagick();
     $imagick->readImage($this->_file);
     $size = null;
     if ($param['size']) {
         $size = $param['size'];
     } else {
         $text = new ImagickDraw();
         $text->setFontSize(12);
         $text->setFont($this->_watermarkFont);
         $im = new Imagick();
         $stringBox12 = $im->queryFontMetrics($text, $overlayText, false);
         $string12 = $stringBox12['textWidth'];
         $size = (int) ($this->_width / 2) * 12 / $string12;
         $im->clear();
         $im->destroy();
         $text->clear();
         $text->destroy();
     }
     $draw = new ImagickDraw();
     $draw->setFont($this->_watermarkFont);
     $draw->setFontSize($size);
     $draw->setFillOpacity($param['opacity']);
     switch ($position) {
         case Gio_Image_Abstract::POS_TOP_LEFT:
             $draw->setGravity(Imagick::GRAVITY_NORTHWEST);
             break;
         case Gio_Image_Abstract::POS_TOP_RIGHT:
             $draw->setGravity(Imagick::GRAVITY_NORTHEAST);
             break;
         case Gio_Image_Abstract::POS_MIDDLE_CENTER:
             $draw->setGravity(Imagick::GRAVITY_CENTER);
             break;
         case Gio_Image_Abstract::POS_BOTTOM_LEFT:
             $draw->setGravity(Imagick::GRAVITY_SOUTHWEST);
             break;
         case Gio_Image_Abstract::POS_BOTTOM_RIGHT:
             $draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
             break;
         default:
             throw new Exception('Do not support ' . $position . ' type of alignment');
             break;
     }
     $draw->setFillColor('#' . $param['color']);
     $imagick->annotateImage($draw, 5, 5, $param['rotation'], $overlayText);
     $imagick->writeImage($this->_file);
     $imagick->clear();
     $imagick->destroy();
     $draw->clear();
     $draw->destroy();
 }
开发者ID:piratevn,项目名称:cms-gio,代码行数:52,代码来源:ImageMagick.php


注:本文中的ImagickDraw::setFillOpacity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。