2024 年日本 PHP 研討會

ImagickDraw::rectangle

(PECL imagick 2, PECL imagick 3)

ImagickDraw::rectangle繪製矩形

描述

public ImagickDraw::rectangle(
    浮點數 $x1,
    浮點數 $y1,
    浮點數 $x2,
    浮點數 (float) $y2
): 布林值 (bool)
警告

此函式目前沒有說明文件;僅提供其參數列表。

使用目前的筆觸、筆觸寬度和填滿設定,繪製一個由兩個座標指定的矩形。

參數

x1

左上角的 x 座標

y1

左上角的 y 座標

x2

右下角的 x 座標

y2

右下角的 y 座標

返回值

不返回任何值。

範例

範例 #1 ImagickDraw::rectangle() 範例

<?php
function rectangle($strokeColor, $fillColor, $backgroundColor) {
$draw = new \ImagickDraw();
$strokeColor = new \ImagickPixel($strokeColor);
$fillColor = new \ImagickPixel($fillColor);

$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeOpacity(1);
$draw->setStrokeWidth(2);

$draw->rectangle(200, 200, 300, 300);
$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");

$imagick->drawImage($draw);

header("Content-Type: image/png");
echo
$imagick->getImageBlob();
}

?>

新增註解

使用者貢獻的註解 1 則註解

garym at binaryfarm dot com
14 年前
<?php

// Draw a simple rectangle or three for the newbies.
// I'm trying to comment these as best I can for a non-OOP person.
// commets or criticism are welcome. Gary Melander

$image = new Imagick(); // Create a new instance an $image class

$width = 600; // Some necessary dimensions
$height = 400;

// $image class now inherits some attributes. i.e. Dimensions, bkgcolor...
$image->newImage( $width, $height, new ImagickPixel( 'lightgray' ) );

$draw = new ImagickDraw(); //Create a new drawing class (?)

$draw->setFillColor('wheat'); // Set up some colors to use for fill and outline
$draw->setStrokeColor( new ImagickPixel( 'green' ) );
$draw->rectangle( 100, 100, 200, 200 ); // Draw the rectangle

// Lets draw another
$draw->setFillColor('navy'); // Set up some colors to use for fill and outline
$draw->setStrokeColor( new ImagickPixel( 'yellow' ) );
$draw->setStrokeWidth(4);
$draw->rectangle( 150, 225, 350, 300 ); // Draw the rectangle

// and another
$draw->setFillColor('magenta'); // Set up some colors to use for fill and outline
$draw->setStrokeColor( new ImagickPixel( 'cyan' ) );
$draw->setStrokeWidth(2);
$draw->rectangle( 380, 100, 400, 350 ); // Draw the rectangle

$image->drawImage( $draw ); // Apply the stuff from the draw class to the image canvas

$image->setImageFormat('jpg'); // Give the image a format

header('Content-type: image/jpeg'); // Prepare the web browser to display an image
echo $image; // Publish it to the world!

//$image->writeImage('someimage.jpg"); // ...Or just write it to a file...

?>
To Top