PHP | GmagickDraw setstrokeopacity() Function

The GmagickDraw::setstrokeopacity() function is an inbuilt function in PHP which is used to specify the opacity of stroked object outlines. The value of opacity lies between 0 to 1.

Syntax:

public GmagickDraw::setstrokeopacity( $stroke_opacity ) : GmagickDraw

Parameters: This function accepts single parameter $stroke_opacity which is used to hold the value of stroke opacity as float type.

Return Value: This function returns the GmagickDraw object on success.

Below programs illustrate the GmagickDraw::setstrokeopacity() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// require_once('path/vendor/autoload.php');
  
// Create an GmagickDraw object to draw into. 
$draw = new \GmagickDraw();
  
// Set the stroke color 
$draw->setStrokeColor('Green');
  
// Set the filled color 
$draw->setFillColor('Red');
  
// Set the stroke opacity 
$draw->setStrokeOpacity(0.5);
  
// Set the stroke width
$draw->setStrokeWidth(9);
  
// Draw the rectangle
$draw->rectangle(40, 30, 200, 260);
  
// Create new gimagick object 
$image = new \Gmagick();
  
// Create new image of given size 
$image->newImage(240, 300, 'White');
  
// Set the image format 
$image->setImageFormat("png");
  
// Draw the image
$image->drawImage($draw);
  
header("Content-Type: image/png");
  
// Display the output image
echo $image->getImageBlob();
?>

chevron_right


Output:
setstrokeopacity

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// require_once('path/vendor/autoload.php');
  
// Create an GmagickDraw object to draw into. 
$draw = new \GmagickDraw();
  
// Set the Stroke Color
$draw->setStrokeColor('Black');
  
// Set the Stroke Opacity
$draw->setStrokeOpacity(0.6);
  
// Set the Stroke Width
$draw->setStrokeWidth(4);
  
//Set the filled color 
$draw->setFillColor('lightgreen');
$points = [
        ['x' => 50 * 6, 'y' => 10 * 5],
        ['x' => 20 * 7, 'y' => 30 * 5], 
        ['x' => 60 * 8, 'y' => 50 * 5], 
        ['x' => 70 * 3, 'y' => 15 * 5],
    ];
  
// Draw the polygon 
$draw->polygon($points);
  
// Create new Gmagick object
$image = new \Gmagick();
  
// Set the image dimensions
$image->newImage(500, 300, '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();
?>

chevron_right


Output:
setstrokeopacity

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.