Thursday, July 4, 2024
HomeLanguagesPhpPHP | ImagickDraw setViewbox() Function

PHP | ImagickDraw setViewbox() Function

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
 

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments