本文整理汇总了PHP中ImagickDraw::rectangle方法的典型用法代码示例。如果您正苦于以下问题:PHP ImagickDraw::rectangle方法的具体用法?PHP ImagickDraw::rectangle怎么用?PHP ImagickDraw::rectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ImagickDraw
的用法示例。
在下文中一共展示了ImagickDraw::rectangle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateImage
private function generateImage()
{
$this->generatedImage = new \Imagick();
$rgbBackgroundColor = $this->getBackgroundColor();
if (null === $rgbBackgroundColor) {
$background = 'none';
} else {
$background = new \ImagickPixel("rgb({$rgbBackgroundColor['0']},{$rgbBackgroundColor['1']},{$rgbBackgroundColor['2']})");
}
$this->generatedImage->newImage($this->pixelRatio * 5, $this->pixelRatio * 5, $background, 'png');
// prepare color
$rgbColor = $this->getColor();
$color = new \ImagickPixel("rgb({$rgbColor['0']},{$rgbColor['1']},{$rgbColor['2']})");
$draw = new \ImagickDraw();
$draw->setFillColor($color);
// draw the content
foreach ($this->getArrayOfSquare() as $lineKey => $lineValue) {
foreach ($lineValue as $colKey => $colValue) {
if (true === $colValue) {
$draw->rectangle($colKey * $this->pixelRatio, $lineKey * $this->pixelRatio, ($colKey + 1) * $this->pixelRatio, ($lineKey + 1) * $this->pixelRatio);
}
}
}
$this->generatedImage->drawImage($draw);
return $this;
}
示例2: drawTriangleStrip
/**
* Draws the triangle strip for the signature
*
* @param string $hexColour Hexadecimal colour value for the whole card
*/
public function drawTriangleStrip($hexColour)
{
// The base for the triangles strip, to be drawn over the plain
$darkTriangles = isset($_GET['darktriangles']);
$backArea = new ImagickDraw();
$backArea->setFillColor(new ImagickPixel($hexColour));
$backArea->rectangle(self::SIG_MARGIN + self::SIG_STROKE_WIDTH, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, $this->baseWidth - self::SIG_STROKE_WIDTH + self::SIG_STROKE_WIDTH / 2 + 1, self::TRIANGLE_STRIP_HEIGHT - self::SIG_STROKE_WIDTH + self::SIG_ROUNDING * 4);
$this->canvas->drawImage($backArea);
$originalTriangles = new Imagick(self::IMG_TRIANGLES);
$originalTriangles->cropImage($this->baseWidth, $this->baseHeight, $this->baseWidth / 2, $this->baseHeight / 2);
$triangles = new Imagick();
$triangles->newImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, new ImagickPixel($hexColour));
$triangles = $triangles->textureImage($originalTriangles);
// The gradient to draw over the triangles
$trianglesGradient1 = new Imagick();
$trianglesGradient1->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . 'none' . '-' . $hexColour);
$trianglesGradient1->setImageOpacity(0.6);
// The second gradient to draw over the triangles
$trianglesGradient2 = new Imagick();
$trianglesGradient2->newPseudoImage($this->baseWidth - self::SIG_STROKE_WIDTH * 2 - 2, self::TRIANGLE_STRIP_HEIGHT + self::SIG_STROKE_WIDTH, 'gradient:' . '#4a4a4a' . '-' . '#313131');
// Composite the black and white gradient onto the triangles
$triangles->compositeImage($trianglesGradient2, Imagick::COMPOSITE_OVERLAY, 0, 0);
$triangles->setImageOpacity($darkTriangles ? 0.2 : 0.1);
// Composite the triangles onto the base
$this->canvas->compositeImage($triangles, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
// Composite the triangles gradient onto the base
$this->canvas->compositeImage($trianglesGradient1, Imagick::COMPOSITE_DEFAULT, self::SIG_MARGIN + self::SIG_STROKE_WIDTH + 1, self::SIG_MARGIN + self::SIG_STROKE_WIDTH * 1.5);
}
示例3: drawBackground
/**
* Draws the background colour for the signature.
* Note that this has no relation to {@link Card}s.
*
* @param $hexColour string Hexadecimal colour value
*/
protected function drawBackground($hexColour)
{
$background = new ImagickDraw();
$background->setFillColor($hexColour);
$background->rectangle(0, 0, $this->canvas->getImageWidth(), $this->canvas->getImageHeight());
$this->canvas->drawImage($background);
}
示例4: renderImage
public function renderImage()
{
//Create a ImagickDraw object to draw into.
$draw = new \ImagickDraw();
$darkColor = new \ImagickPixel('brown');
//http://www.imagemagick.org/Usage/compose/#compose_terms
$draw->setStrokeColor($darkColor);
$draw->setFillColor('white');
$draw->setStrokeWidth(2);
$draw->setFontSize(72);
$draw->setStrokeOpacity(1);
$draw->setStrokeColor($darkColor);
$draw->setStrokeWidth(2);
$draw->setFont("../fonts/CANDY.TTF");
$draw->setFontSize(140);
$draw->setFillColor('none');
$draw->rectangle(0, 0, 1000, 300);
$draw->setFillColor('white');
$draw->annotation(50, 180, "Lorem Ipsum!");
$imagick = new \Imagick(realpath("images/TestImage.jpg"));
$draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
//Create an image object which the draw commands can be rendered into
$imagick = new \Imagick();
$imagick->newImage(1000, 300, "SteelBlue2");
$imagick->setImageFormat("png");
//Render the draw commands in the ImagickDraw object
//into the image.
$imagick->drawImage($draw);
//Send the image to the browser
header("Content-Type: image/png");
echo $imagick->getImageBlob();
}
示例5: fill
/**
* Flood the image with a color fill.
*
* @param int $r
* @param int $g
* @param int $b
* @return Imagick
*/
public function fill($r, $g, $b)
{
$draw = new \ImagickDraw();
$draw->setFillColor($this->image->getColor([(int) $r, (int) $g, (int) $b]));
$draw->rectangle(0, 0, $this->image->getWidth(), $this->image->getHeight());
$this->image->resource()->drawImage($draw);
return $this;
}
示例6: colorize
public function colorize($color, $alpha = 1)
{
$draw = new ImagickDraw();
$draw->setFillColor($color);
if (is_float($alpha)) {
$draw->setFillAlpha($alpha);
}
$geometry = $this->getImageGeometry();
$width = $geometry['width'];
$height = $geometry['height'];
$draw->rectangle(0, 0, $width, $height);
$this->drawImage($draw);
}
示例7: test_shape
function test_shape(&$canvas)
{
$draw = new ImagickDraw();
$draw->setFillColor('transparent');
$draw->setStrokeColor('#F02B88');
$draw->setStrokeWidth(9);
$draw->translate(200, 100);
$draw->rectangle(-50, -50, 50, 50);
$draw->translate(200, 100);
$draw->ellipse(0, 0, 100, 80, 0, 360);
$draw->skewX(-30);
$draw->translate(200, 100);
$draw->circle(0, 0, 50, 50);
$canvas->drawImage($draw);
}
示例8: applyToImage
/**
* Draw rectangle to given image at certain position
*
* @param Image $image
* @param integer $x
* @param integer $y
* @return boolean
*/
public function applyToImage(Image $image, $x = 0, $y = 0)
{
$rectangle = new \ImagickDraw();
// set background
$bgcolor = new Color($this->background);
$rectangle->setFillColor($bgcolor->getPixel());
// set border
if ($this->hasBorder()) {
$border_color = new Color($this->border_color);
$rectangle->setStrokeWidth($this->border_width);
$rectangle->setStrokeColor($border_color->getPixel());
}
$rectangle->rectangle($this->x1, $this->y1, $this->x2, $this->y2);
$image->getCore()->drawImage($rectangle);
return true;
}
示例9: rectangle
/**
* Draw a rectangle on the image.
*
* @param int $x
* @param int $y
* @param int $w
* @param int $h
* @return Imagick
*/
public function rectangle($x, $y, $w, $h = null)
{
$x2 = $x + $w;
$y2 = $y + (null === $h ? $w : $h);
$draw = new \ImagickDraw();
if (null !== $this->fillColor) {
$draw->setFillColor($this->image->getColor($this->fillColor, $this->opacity));
}
if ($this->strokeWidth > 0) {
$draw->setStrokeColor($this->image->getColor($this->strokeColor, $this->opacity));
$draw->setStrokeWidth($this->strokeWidth);
}
$draw->rectangle($x, $y, $x2, $y2);
$this->image->resource()->drawImage($draw);
return $this;
}
示例10: fill
public function fill($x1, $y1, $x2, $y2, $color = array(0, 0, 0, 100))
{
is_string($color) and $color = $this->create_hex_color($color);
if (is_array($color)) {
if (\Arr::is_assoc($color)) {
extract($color);
} else {
if (count($color) > 3) {
list($red, $green, $blue, $alpha) = $color;
} else {
list($red, $green, $blue) = $color;
$alpha = 100;
}
}
$alpha = round($alpha / 100, 1);
$color = new \ImagickPixel('rgba(' . $red . ', ' . $green . ', ' . $blue . ', ' . str_replace(',', '.', $alpha) . ')');
}
$fill = new \ImagickDraw();
$fill->setfillcolor($color);
$fill->rectangle($x1, $y1, $x2, $y2);
$this->imagick->drawimage($fill);
return $this;
}
示例11: renderImage
function renderImage()
{
//Create a ImagickDraw object to draw into.
$draw = new \ImagickDraw();
$darkColor = new \ImagickPixel('brown');
//http://www.imagemagick.org/Usage/compose/#compose_terms
$draw->setStrokeColor($darkColor);
$draw->setFillColor('white');
$draw->setStrokeWidth(2);
$draw->setFontSize(72);
$draw->setStrokeOpacity(1);
$draw->setStrokeColor($darkColor);
$draw->setStrokeWidth(2);
$draw->setFont("../fonts/CANDY.TTF");
$draw->setFontSize(140);
$draw->setFillColor('none');
$draw->rectangle(0, 0, 1000, 300);
$draw->setFillColor('white');
$draw->annotation(50, 180, "Lorem Ipsum!");
$imagick = new \Imagick(realpath("images/TestImage.jpg"));
// $compositeModes = [
//
// \Imagick::COMPOSITE_NO, \Imagick::COMPOSITE_ADD, \Imagick::COMPOSITE_ATOP, \Imagick::COMPOSITE_BLEND, \Imagick::COMPOSITE_BUMPMAP, \Imagick::COMPOSITE_CLEAR, \Imagick::COMPOSITE_COLORBURN, \Imagick::COMPOSITE_COLORDODGE, \Imagick::COMPOSITE_COLORIZE, \Imagick::COMPOSITE_COPYBLACK, \Imagick::COMPOSITE_COPYBLUE, \Imagick::COMPOSITE_COPY, \Imagick::COMPOSITE_COPYCYAN, \Imagick::COMPOSITE_COPYGREEN, \Imagick::COMPOSITE_COPYMAGENTA, \Imagick::COMPOSITE_COPYOPACITY, \Imagick::COMPOSITE_COPYRED, \Imagick::COMPOSITE_COPYYELLOW, \Imagick::COMPOSITE_DARKEN, \Imagick::COMPOSITE_DSTATOP, \Imagick::COMPOSITE_DST, \Imagick::COMPOSITE_DSTIN, \Imagick::COMPOSITE_DSTOUT, \Imagick::COMPOSITE_DSTOVER, \Imagick::COMPOSITE_DIFFERENCE, \Imagick::COMPOSITE_DISPLACE, \Imagick::COMPOSITE_DISSOLVE, \Imagick::COMPOSITE_EXCLUSION, \Imagick::COMPOSITE_HARDLIGHT, \Imagick::COMPOSITE_HUE, \Imagick::COMPOSITE_IN, \Imagick::COMPOSITE_LIGHTEN, \Imagick::COMPOSITE_LUMINIZE, \Imagick::COMPOSITE_MINUS, \Imagick::COMPOSITE_MODULATE, \Imagick::COMPOSITE_MULTIPLY, \Imagick::COMPOSITE_OUT, \Imagick::COMPOSITE_OVER, \Imagick::COMPOSITE_OVERLAY, \Imagick::COMPOSITE_PLUS, \Imagick::COMPOSITE_REPLACE, \Imagick::COMPOSITE_SATURATE, \Imagick::COMPOSITE_SCREEN, \Imagick::COMPOSITE_SOFTLIGHT, \Imagick::COMPOSITE_SRCATOP, \Imagick::COMPOSITE_SRC, \Imagick::COMPOSITE_SRCIN, \Imagick::COMPOSITE_SRCOUT, \Imagick::COMPOSITE_SRCOVER, \Imagick::COMPOSITE_SUBTRACT, \Imagick::COMPOSITE_THRESHOLD, \Imagick::COMPOSITE_XOR,
//
// ];
$draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
//Create an image object which the draw commands can be rendered into
$imagick = new \Imagick();
$imagick->newImage(1000, 300, "SteelBlue2");
$imagick->setImageFormat("png");
//Render the draw commands in the ImagickDraw object
//into the image.
$imagick->drawImage($draw);
//Send the image to the browser
header("Content-Type: image/png");
echo $imagick->getImageBlob();
}
示例12: 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;
}
示例13: colorizeWall
private function colorizeWall()
{
$wall = new Imagick($this->wallImage);
$im = new Imagick();
$im->newimage(1280, 720, $this->baseColor, 'png');
$wall->compositeimage($im, Imagick::COMPOSITE_MULTIPLY, 0, 0);
$im->clear();
// darken image
if ($this->darkenValue < 100 && $this->darkenValue >= 50) {
$wallAdjust = clone $wall;
$wallAdjust->modulateimage($this->darkenValue, 100, 100);
$wall->compositeimage($wallAdjust, Imagick::COMPOSITE_MULTIPLY, 0, 0);
$wallAdjust->clear();
}
// lighten image
if ($this->lightenValue > 0) {
$wallAdjust = clone $wall;
$draw = new ImagickDraw();
$draw->setFillColor('#ffffff');
$draw->setfillopacity($this->lightenValue / 100);
$geometry = $wallAdjust->getImageGeometry();
$width = $geometry['width'];
$height = $geometry['height'];
$draw->rectangle(0, 0, $width, $height);
$wallAdjust->drawImage($draw);
$wall->compositeimage($wallAdjust, Imagick::COMPOSITE_DEFAULT, 0, 0);
$wallAdjust->clear();
}
// apply hue/saturation
$wall->modulateimage(100, $this->saturationValue, $this->hueValue);
$wall->compositeimage($this->mask, Imagick::COMPOSITE_DSTIN, 0, 0);
return $wall;
}
示例14: execute
/**
* Fills image with color or pattern
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$filling = $this->argument(0)->value();
$x = $this->argument(1)->type('digit')->value();
$y = $this->argument(2)->type('digit')->value();
$imagick = $image->getCore();
try {
// set image filling
$source = new Decoder();
$filling = $source->init($filling);
} catch (\Intervention\Image\Exception\NotReadableException $e) {
// set solid color filling
$filling = new Color($filling);
}
// flood fill if coordinates are set
if (is_int($x) && is_int($y)) {
// flood fill with texture
if ($filling instanceof Image) {
// create tile
$tile = clone $image->getCore();
// mask away color at position
$tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
// create canvas
$canvas = clone $image->getCore();
// fill canvas with texture
$canvas = $canvas->textureImage($filling->getCore());
// merge canvas and tile
$canvas->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
// replace image core
$image->setCore($canvas);
// flood fill with color
} elseif ($filling instanceof Color) {
// create canvas with filling
$canvas = new \Imagick();
$canvas->newImage($image->getWidth(), $image->getHeight(), $filling->getPixel(), 'png');
// create tile to put on top
$tile = clone $image->getCore();
// mask away color at pos.
$tile->transparentPaintImage($tile->getImagePixelColor($x, $y), 0, 0, false);
// save alpha channel of original image
$alpha = clone $image->getCore();
// merge original with canvas and tile
$image->getCore()->compositeImage($canvas, \Imagick::COMPOSITE_DEFAULT, 0, 0);
$image->getCore()->compositeImage($tile, \Imagick::COMPOSITE_DEFAULT, 0, 0);
// restore alpha channel of original image
$image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
}
} else {
if ($filling instanceof Image) {
// fill whole image with texture
$image->setCore($image->getCore()->textureImage($filling->getCore()));
} elseif ($filling instanceof Color) {
// fill whole image with color
$draw = new \ImagickDraw();
$draw->setFillColor($filling->getPixel());
$draw->rectangle(0, 0, $image->getWidth(), $image->getHeight());
$image->getCore()->drawImage($draw);
}
}
return true;
}
示例15: whirlyGif
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider)
{
$aniGif = new \Imagick();
$aniGif->setFormat("gif");
$width = 500;
$height = $width;
$numberDots = intval($numberDots);
if ($numberDots < 1) {
$numberDots = 1;
}
$maxFrames = $numberFrames;
$frameDelay = ceil($loopTime / $maxFrames);
$scale = 1;
$startColor = new \ImagickPixel('red');
$dots = [];
for ($i = 0; $i < $numberDots; $i++) {
$colorInfo = $startColor->getHSL();
//Rotate the hue by 180 degrees
$newHue = $colorInfo['hue'] + $i / $numberDots;
if ($newHue > 1) {
$newHue = $newHue - 1;
}
//Set the ImagickPixel to the new color
$color = new \ImagickPixel('#ffffff');
$colorInfo['saturation'] *= 0.95;
$color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);
$dots[] = new Dot($color, $i, $numberDots, $width, $height);
}
for ($frame = 0; $frame < $maxFrames; $frame++) {
$draw = new \ImagickDraw();
$draw->setStrokeColor('none');
$draw->setFillColor('none');
$draw->rectangle(0, 0, $width, $height);
$draw->translate($width / 2, $height / 2);
foreach ($dots as $dot) {
/** @var $dot Dot */
$dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider);
}
//Create an image object which the draw commands can be rendered into
$imagick = new \Imagick();
$imagick->newImage($width * $scale, $height * $scale, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS);
//Render the draw commands in the ImagickDraw object
//into the image.
$imagick->drawImage($draw);
$imagick->setImageDelay($frameDelay);
$aniGif->addImage($imagick);
$imagick->destroy();
}
$aniGif->setImageFormat('gif');
$aniGif->setImageIterations(0);
//loop forever
$aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS);
header("Content-Type: image/gif");
echo $aniGif->getImagesBlob();
}