GmagickDraw::scale()函數是PHP中的內置函數,用於設置比例因子並將其應用於當前坐標空間的水平和垂直方向。
用法:
public GmagickDraw::scale( $x, $y ) : GmagickDraw
參數:該函數接受上麵提到並在下麵描述的兩個參數:
- $x:此參數用於保存水平因子的值。
- $y:此參數用於保存垂直係數的值。
返回值:成功時,此函數返回GmagickDraw對象。
以下示例程序旨在說明PHP中的GmagickDraw::scale()函數:
示例1:
<?php
// require_once('path/vendor/autoload.php');
// Create a GmagickDraw object
$draw = new \GmagickDraw ();
// Set the Stroke Color
$draw->setStrokeColor('Green');
// Set the Fill Color
$draw->setFillColor('Red');
// Set the stroke width
$draw->setStrokeWidth(7);
// Draw the rectangle
$draw->rectangle(40, 30, 200, 260);
// Set the scale
$draw->scale(1.4, 1.4);
// Set the fill color
$draw->setFillColor('lightgreen');
// Draw the rectangle
$draw->rectangle(40, 30, 200, 260);
// Create an Gmagick object
$image = new \Gmagick();
// Set the image dimensions
$image->newImage(800, 400, 'White');
// Set the image format
$image->setImageFormat("png");
// Draw the image
$image->drawImage($draw);
header("Content-Type: image/png");
// Display the iamge
echo $image->getImageBlob();
?>
輸出:
示例2:
<?php
// require_once('path/vendor/autoload.php');
// Create an Gmagick Draw object
$draw = new \GmagickDraw();
// Set the stroke color
$strokeColor = new \GmagickPixel('Green');
// Set the fill color
$fillColor = new \GmagickPixel('Red');
// Set the stroke opacity
$draw->setStrokeOpacity(1);
// Set the stroke color
$draw->setStrokeColor('Green');
// Set the Fill Color
$draw->setFillColor('Red');
// Set the stroke width
$draw->setStrokeWidth(2);
$smoothPointsSet = [
[
['x' => 10.0 * 5, 'y' => 10.0 * 5],
['x' => 30.0 * 5, 'y' => 90.0 * 5],
['x' => 25.0 * 5, 'y' => 10.0 * 5],
['x' => 50.0 * 5, 'y' => 50.0 * 5],
]
];
foreach ($smoothPointsSet as $points) {
$draw->bezier($points);
}
// Set the stroke color
$draw->setStrokeColor('black');
// Set the fill color
$draw->setFillColor('lightgreen');
// Set the scale
$draw->scale(1.5, 1.5);
foreach ($smoothPointsSet as $points) {
$draw->bezier($points);
}
// Create an gmagick object
$gmagick = new \Gmagick();
// Set the image dimensions
$gmagick ->newImage(400, 500, 'White');
// Set the image format
$gmagick ->setImageFormat("png");
// Draw the image
$gmagick ->drawImage($draw);
header("Content-Type: image/png");
// Display the image
echo $gmagick ->getImageBlob();
?>
輸出:
參考: http://php.net/manual/en/gmagickdraw.scale.php
相關用法
- CSS scale()用法及代碼示例
- PHP ImagickKernel scale()用法及代碼示例
- PHP ImagickDraw scale()用法及代碼示例
- PHP GmagickDraw arc()用法及代碼示例
- PHP GmagickDraw getfontstyle()用法及代碼示例
- PHP GmagickDraw getfillopacity()用法及代碼示例
- PHP GmagickDraw polygon()用法及代碼示例
- PHP GmagickDraw polyline()用法及代碼示例
- PHP GmagickDraw annotate()用法及代碼示例
- PHP GmagickDraw rotate()用法及代碼示例
- PHP GmagickDraw setfont()用法及代碼示例
- PHP GmagickDraw gettextencoding()用法及代碼示例
- PHP GmagickDraw gettextdecoration()用法及代碼示例
- PHP GmagickDraw getfontweight()用法及代碼示例
- PHP GmagickDraw getstrokecolor()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | GmagickDraw scale() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。