📜  PHP | imagickdraw translate()函数

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

PHP | imagickdraw translate()函数

ImagickDraw::translate()函数是PHP中的一个内置函数,用于将平移应用于当前坐标系。它对当前坐标系应用平移,将坐标系原点移动到指定坐标。

句法:

bool ImagickDraw::translate( $x, $y )

参数:该函数接受上面提到的两个参数,如下所述:

  • $x:这个参数用来保存x平移坐标的值。
  • $y:这个参数用来保存y平移坐标的值。

返回值:此函数不返回任何值。

下面的程序说明了PHP中的ImagickDraw::translate()函数

方案一:

setStrokeColor('black');
  
// Set the Image Filled Color
$draw->setFillColor('red');
  
// Draw the circle
$draw->circle(250, 250, 100, 150);
   
// Set the Image Filled Color
$draw->setFillColor('green');
  
// Set the translation points
$draw->translate(90, 30);
  
// Draw the circle
$draw->circle(350, 350, 250, 350);
   
// Create new imagick object
$image = new Imagick();
  
// Set the dimensions of the image
$image->newImage(500, 500, 'white');
  
// Set the image format
$image->setImageFormat("png");
  
// Draw the image
$image->drawImage($draw);
header("Content-Type: image/png");
  
// Display the image
echo $image->getImageBlob();
?>

输出:
翻译()

方案二:

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 image filled color 
$draw->setFillColor('green');
   
// Set the translation points
$draw->translate(10, 30);
$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 image filled color 
$draw->setFillColor('blue');
   
// Set the translation points
$draw->translate(10, 30);
$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 image filled color
$draw->setFillColor('yellow');
   
// Set the translation points
$draw->translate(10, 30);
$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);
   
// Create new imagick object
$image = new Imagick();
   
// Set the image dimensions
$image->newImage(400, 400, 'white');
   
// Set the image format
$image->setImageFormat("png");
   
// Draw the image 
$image->drawImage($draw);
header("Content-Type: image/png");
   
// Display the image
echo $image->getImageBlob();
?>

输出:

参考: http: PHP。 PHP