Open In App

PHP | ImagickDraw getFontWeight() Function

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

The ImagickDraw::getFontWeight() function is an inbuilt function in PHP which is used to get the font-weight used when annotating with text. Font weight actually signifies the boldness of the font, more the font-weight the more the bold text will be. It can be anything from 100 to 900.

Syntax:

int ImagickDraw::getFontWeight( void )

Parameters: This function doesn’t accept any parameter.

Return Value: This function returns an integer value containing the font weight or 0 when no weight is set.

Exceptions: This function throws ImagickException on error.

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

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Get the font Weight
$fontWeight = $draw->getFontWeight();
echo $fontWeight;
?>


Output:

0 // which is the default value.

Program 2:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the font Weight
$draw->setFontWeight(110);
  
// Get the font Weight
$fontWeight = $draw->getFontWeight();
echo $fontWeight;
?>


Output:

110

Program 3:




<?php
   
// Create a new imagick object
$imagick = new Imagick();
   
// Create a image on imagick object
$imagick->newImage(800, 250, '#bfc7d6');
   
// Create a new ImagickDraw object
$draw = new ImagickDraw();
   
// Set the font size
$draw->setFontSize(30);
   
// Annotate a text
$draw->annotation(50, 100, 
                  'The Font weight here is default.');
   
// Set the font weight
$draw->setFontWeight(900);
   
// Annotate a text
$draw->annotation(50, 200, 
                  'The Font weight here is ' 
                  . $draw->getFontWeight() . '.');
   
// 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.getfontweight.php



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

Similar Reads