Open In App

PHP | ImagickDraw setViewbox() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::setViewbox() function is an inbuilt function of PHP which is used to set the overall canvas size. This function set the overall canvas size to be recorded with the drawing vector data. It will be specified using the same size as the canvas image. 
Syntax: 
 

bool ImagickDraw::setViewbox( $x1, $y1, $x2, $y2 )

Parameters: This function accepts four parameter as mentioned above and described below:
 

  • $x1: This parameter is used to hold the value of left x coordinate.
  • $y1: This parameter is used to hold the value of left y coordinate.
  • $x2: This parameter is used to hold the value of right x coordinate.
  • $y2: This parameter is used to hold the value of right y coordinate.

Return Value: This function does not return any value.
Below programs illustrate the ImagickDraw::setViewbox() function in PHP:
Program 1: 
 

php




<?php
 
// Create new ImagickDraw object
$draw = new \ImagickDraw();
 
// Set the Stroke color
$draw->setStrokeColor('black');
 
// Set the image filled color
$draw->setFillColor('yellow');
 
// Set the Stroke Width
$draw->setStrokeWidth(2);
 
// Set the Font Size
$draw->setFontSize(72);
 
// Draw the rectangle
$draw->rectangle(150, 450, 450, 300);
 
// Set the view box
$draw->setviewbox(0, 0, 200, 200);
 
// Set the image filled color
$draw->setFillColor('green');
 
// Draw the rectangle
$draw->rectangle(150, 450, 250, 300);
 
// Set the image filled color
$draw->setFillColor('red');
 
// Draw the circle
$draw->circle(100, 100, 125, 0);
 
// Create new Imagick object 
$imagick = new \Imagick();
 
// Set the i age dimensions
$imagick->newImage(500, 500, 'white');
 
// Set the image format
$imagick->setImageFormat("png");
 
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
 
// Display the image
echo $imagick->getImageBlob();
?>


Output: 
 

setViewBox

Program 2: 
 

php




<?php
 
// Create an ImagickDraw object
$draw = new \ImagickDraw();
  
// Set the stroke color
$draw->setStrokeColor('black');
  
// Set the image filled color
$draw->setFillColor('red');
$points = [['x' => 40 * 5, 'y' => 10 * 5],
           ['x' => 70 * 5, 'y' => 50 * 5],
           ['x' => 60 * 5, 'y' => 15 * 5], ];
  
// Draw the polygon
$draw->polygon($points);
  
// Set the view box
$draw->setviewbox(0, 0, 200, 200);
  
// Set the image filled color
$draw->setFillColor('green');
$points = [['x' => 40 * 7, 'y' => 10 * 4],
           ['x' => 70 * 2, 'y' => 50 * 3],
           ['x' => 60 * 3, 'y' => 15 * 3], ];
  
// Draw the polygon
$draw->polygon($points);
  
// Set the image filled color
$draw->setFillColor('yellow');
  
// Draw the circle
$draw->circle(100, 100, 125, 0);
  
// Create new Imagick object 
$imagick = new \Imagick();
  
// Set the image dimensions
$imagick->newImage(400, 300, 'white');
  
// Set the image format
$imagick->setImageFormat("png");
  
// Draw the image
$imagick->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $imagick->getImageBlob();
?>


Output: 
 

setViewBox

Reference: http://php.net/manual/en/imagickdraw.setviewbox.php
 



Last Updated : 08 Feb, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads