Open In App

PHP | ImagickDraw getFillOpacity() Function

Last Updated : 23 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

The ImagickDraw::getFillOpacity() function is an inbuilt function in PHP which is used to get the opacity used when drawing using the fill color or fill texture. Fully opaque is 1 and fully transparent is 0.

Syntax:

float ImagickDraw::getFillOpacity( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns an float value containing the opacity.

Exceptions: This function throws ImagickException on error.

Below given programs illustrate the ImagickDraw::getFillOpacity() function in PHP:

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Get the Fill Opacity
$fillOpacity = $draw->getFillOpacity();
echo $fillOpacity;
?>


Output:

1 // which is the default value.

Program 2:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the Fill Opacity
$draw->setFillOpacity(0.6);
  
// Get the Fill Opacity
$fillOpacity = $draw->getFillOpacity();
echo $fillOpacity;
?>


Output:

0.6

Program 3:




<?php
  
// Create a new imagick object
$imagick = new Imagick();
  
// Create a image on imagick object
$imagick->newImage(800, 250, 'black');
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the fill color
$draw->setFillColor('yellow');
  
// Set the font size
$draw->setFontSize(20);
  
// Annotate a text
$draw->annotation(50, 100, 'The fill opacity here is ' 
                           . $draw->getFillOpacity());
  
// Set the fill opacity
$draw->setFillOpacity(0.4);
  
// Annotate a text
$draw->annotation(50, 200, 'The fill opacity here is ' 
                           . $draw->getFillOpacity());
  
// Render the draw commands
$imagick->drawImage($draw);
  
// Show the output
$imagick->setImageFormat('png');
header("Content-Type: image/png");
echo $imagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/imagickdraw.getfillopacity.php



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads