Open In App

PHP | GmagickDraw scale() Function

Last Updated : 03 May, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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 image
echo $gmagick ->getImageBlob();
?>


Output: 
 

Reference: http://php.net/manual/en/gmagickdraw.scale.php
 



Similar Reads

PHP | GmagickDraw rectangle() Function
The GmagickDraw::rectangle() function is an inbuilt function in PHP which is used to draw the rectangle. Syntax: public GmagickDraw::rectangle( $x1, $y1, $x2, $y2 )   Parameters:This function accepts four parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of the top left corner. $y1: This paramete
2 min read
PHP | GmagickDraw setstrokewidth() Function
The GmagickDraw::setstrokewidth() function is an inbuilt function in PHP which is used to set the width of the stroke used to draw object outlines. Syntax: public GmagickDraw::setstrokewidth( $stroke_width ) : GmagickDraw Parameters: This function accepts single parameter $stroke_width which is used to hold the value of stroke width. It is a float
2 min read
PHP | GmagickDraw setfontstyle() Function
The GmagickDraw::setfontstyle() function is an inbuilt function in PHP that is used to set the font style to use when annotating with text. Style enumeration acts as a wild-card don't care option. Syntax: public GmagickDraw::setfontstyle( $style ) : GmagickDraw Parameters: This function accepts a single parameter $style which is used to hold the va
2 min read
PHP | GmagickDraw setfontweight() Function
The GmagickDraw::setfontweight() function is an inbuilt function in PHP that is used to set the font weight. Syntax: public GmagickDraw::setfontweight( $font_weight ) : GmagickDraw Parameters: This function accepts a single parameter $font_weight which is used to hold the value of font-weight as an integer type. Return Value: This function returns
2 min read
PHP | GmagickDraw settextdecoration() Function
The GmagickDraw ::settextdecoration() function is an inbuilt function in PHP that is used to specify the decoration to be applied when annotating with text. Syntax: public GmagickDraw::settextdecoration( $decoration ) : GmagickDraw Parameters: This function accepts a single parameter $decoration which is used to hold the value of DECORATION_ consta
2 min read
PHP | GmagickDraw setfillopacity() Function
The GmagickDraw ::setfillopacity() function is an inbuilt function in PHP which is used to set the opacity of a drawing image. It is used when drawing the image using the filled color or filled texture. Syntax: public GmagickDraw::setfillopacity( $fill_opacity ) : GmagickDraw Parameters: This function accepts single parameter $fill_opacity which is
2 min read
PHP | GmagickDraw setstrokecolor() Function
The GmagickDraw ::setstrokecolor() function is an inbuilt function in PHP which is used to set the color used for stroking object outlines. Syntax: public GmagickDraw::setstrokecolor( $color ) : GmagickDraw Parameters: This function accepts single parameter $color which is used to hold the color value. Return Value: This function returns the Gmagic
2 min read
PHP | GmagickDraw setstrokeopacity() Function
The GmagickDraw::setstrokeopacity() function is an inbuilt function in PHP that is used to specify the opacity of stroked object outlines. The value of opacity lies between 0 and 1. Syntax: public GmagickDraw::setstrokeopacity( $stroke_opacity ) : GmagickDraw Parameters: This function accepts a single parameter $stroke_opacity which is used to hold
2 min read
PHP | GmagickDraw roundrectangle() Function
The GmagickDraw::roundrectangle() function is an inbuilt function in PHP which is used to draw a rounded rectangle. Syntax: public GmagickDraw::rectangle( $x1, $y1, $x2, $y2, $rx, $ry)   Parameters:This function accepts four parameters as mentioned above and described below: $x1: This parameter takes the value of x coordinate of the top left corner
2 min read
PHP | GmagickDraw point() Function
The GmagickDraw::point() function is an inbuilt function in PHP which is used to draw a point. This function uses current stroke color and stroke thickness at the specified coordinates. Syntax: public GmagickDraw::point( $x, $y )   Parameters:This function accepts two parameters as mentioned above and described below: $x: This parameter takes the v
2 min read