📜  PHP | imagickdraw setviewbox()函数

📅  最后修改于: 2022-05-13 01:56:21.265000             🧑  作者: Mango

PHP | imagickdraw setviewbox()函数

ImagickDraw::setViewbox()函数是PHP的一个内置函数,用于设置整体画布大小。此函数设置要与绘图矢量数据一起记录的整体画布大小。它将使用与画布图像相同的大小来指定。
句法:

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

参数:此函数接受四个参数,如上所述,如下所述:

  • $x1:此参数用于保存左x坐标的值。
  • $y1:此参数用于保存左y坐标的值。
  • $x2:该参数用于保存右x坐标的值。
  • $y2:此参数用于保存右 y 坐标的值。

返回值:此函数不返回任何值。
下面的程序说明了PHP中的ImagickDraw::setViewbox()函数
方案一:

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


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


输出:

设置视图框

方案二:

PHP

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

输出:

设置视图框

参考: http: PHP。 PHP