PHP 8.5.0 Alpha 1 available for testing

ImagickDraw::rectangle

(PECL imagick 2, PECL imagick 3)

ImagickDraw::rectangleDraws a rectangle

Description

public ImagickDraw::rectangle(
    float $top_left_x,
    float $top_left_y,
    float $bottom_right_x,
    float $bottom_right_y
): bool
Warning

This function is currently not documented; only its argument list is available.

Draws a rectangle given two coordinates and using the current stroke, stroke width, and fill settings.

Parameters

top_left_x

x coordinate of the top left corner

top_left_y

y coordinate of the top left corner

bottom_right_x

x coordinate of the bottom right corner

bottom_right_y

y coordinate of the bottom right corner

Return Values

No value is returned.

Examples

Example #1 ImagickDraw::rectangle() example

<?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();
}

?>

add a note

User Contributed Notes 1 note

up
8
garym at binaryfarm dot com
15 years ago
<?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

Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant