+

PHP ImagickDraw function setViewbox ()

Syntax:
bool ImagickDraw::setViewbox ($x1, $y1, $x2, $y2)
Parameters:This function takes four parameters as above and described below:
  • $x1:This parameter is used to store the value of the left x coordinates.
  • $y1:this parameter is used to store the value of the left y coordinate.
  • $x2:this parameter is used to store the right x coordinate value.
  • $y2:this parameter is used to store the right y coordinate value.
Return value :this function does not return any value.The following programs illustrate the ImagickDraw::setViewbox() functionin PHP:Program 1: < tbody>  
// Create a new ImagickDraw object $draw = new ImagickDraw();  
// Set the stroke color $draw -> setStrokeColor ( `black` );  
// Set the fill color of the image $draw -> setFillColor ( `yellow` );  
// Set the stroke width $draw -> setStrokeWidth (2);  
// Set font size $draw -> setFontSize (72);  
// Draw a rectangle $draw -> rectangle (150, 450, 450, 300);  
// Set the viewport $draw -> setviewbox (0, 0, 200, 200);  
// Set the fill color of the image $draw -> setFillColor ( `green` );  
// Draw a rectangle $draw -> rectangle (150, 450, 250, 300);  
// Set the fill color of the image $draw -> setFillColor ( `red` );  
// Draw a circle $draw -> circle (100, 100, 125, 0);  
// Create a new Imagick object $imagick = new Imagick();  
// Set dimensions $imagick -> newImage (500, 500, `white` );  
// Set image format $imagick -> setImageFormat ( "png" );  
// Draw image $imagick -> drawImage ( $draw ); header ( "Content-Type: image / png" );  
// Show image echo $imagick -> getImageBlob(); ?>
Output: Program 2:  
// Create ImagickDraw object $draw = new ImagickDraw();  
// Set stroke color $draw -> setStrokeColor ( `black` );  
// Set the fill color of the image $draw -> setFillColor ( `red` ); $points = [[ `x ` = > 40 * 5, `y` = > 10 * 5], [ `x` = > 70 * 5, `y` = > 50 * 5], [ `x` = > 60 * 5, `y` = > 15 * 5],];  
// Draw a polygon $draw -> polygon ( $points );  
// Set the viewport $draw -> setviewbox (0, 0, 200, 200);  
// Set the fill color of the image $draw -> setFillColor ( `green` ); $points = [[ `x ` = > 40 * 7, `y` = > 10 * 4], [ `x` = > 70 * 2, `y` = > 50 * 3], [ `x` = > 60 * 3, `y` = > 15 * 3],];  
// Draw polygon $draw -> polygon ( $points );  
// Set the fill color of the image $draw -> setFillColor ( `yellow` );  
// Draw a circle $draw -> circle (100, 100, 125, 0);  
// Create a new Imagick object $imagick = new Imagick();  
// Set image dimensions $imagick -> newImage (400, 300, `white` );  
// Set image format $imagick -> setImageFormat ( "png" );  
// Draw image $imagick -> drawImage ( $draw ); header ( "Content-Type: image / png" );  
// Show image echo $imagick -> getImageBlob(); ?>
Output: Link: http://php.net/manual/en/imagickdraw.setviewbox.php
Get Solution for free from DataCamp guru