PHP | GmagickDraw scale() Function

The GmagickDraw::scale() function is an inbuilt function in PHP which is used to set the scaling factor and apply it to the horizontal and vertical directions to the current coordinate space.
Syntax:Â
Â
public GmagickDraw::scale( $x, $y ) : GmagickDraw
Parameters: This function accepts two parameter as mentioned above and described below:Â
Â
- $x: This parameter is used to hold the value of horizontal factor.
- $y: This parameter is used to hold the value of vertical factor.
Return Value: This function returns GmagickDraw object on success.
Below programs illustrate the GmagickDraw::scale() function in PHP:
Program 1:Â
Â
php
<?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 image echo $image->getImageBlob();?> |
Output:Â
Â
Program 2:Â
Â
php
<?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 imageecho $gmagick ->getImageBlob();?> |
Output:Â
Â
Reference: http://php.net/manual/en/gmagickdraw.scale.php
Â




