Friday, September 5, 2025
HomeLanguagesPHP | GmagickDraw getfontstyle() Function

PHP | GmagickDraw getfontstyle() Function

The GmagickDraw::getfontstyle() function is an inbuilt function in PHP which is used to get the font style used when annotating with text.

Syntax:

int GmagickDraw::getfontstyle( void )

Parameters: This function doesn’t accept any parameters.

Return Value: This function returns an integer value corresponding to one of the STYLE constants.
The list of STYLE constants are given below:

  • Gmagick::STYLE_NORMAL (Integer)
  • Gmagick::STYLE_ITALIC (Integer)
  • Gmagick::STYLE_OBLIQUE (Integer)
  • Gmagick::STYLE_ANY (Integer)

Exceptions: This function throws GmagickDrawException on error.

Below given programs illustrate the GmagickDraw::getfontstyle() function in PHP:

Used Image:

Program 1:




<?php
  
// Create a new GmagickDraw object 
$draw = new GmagickDraw(); 
  
// Get the font Style 
$fontStyle = $draw->getfontstyle(); 
echo $fontStyle
?> 


Output:

0 // Which is the default value.

Program 3:




<?php
  
// Create a new GmagickDraw object 
$draw = new GmagickDraw(); 
  
// Set the font style
$draw->setfontstyle(2);
    
// Get the font Style 
$fontStyle = $draw->getfontstyle(); 
echo $fontStyle
?> 


Output:

2

Program 2:




<?php
  
// Create a new Gmagick object
$gmagick = new Gmagick('neveropen.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the color
$draw->setFillColor('#0E0E0E');
   
// Set the font size
$draw->setfontsize(40);
  
// Draw rectangle for background
$draw->rectangle(-10, -10, 800, 400);
  
// Set the fill color
$draw->setFillColor('white');
  
// Set the font style to Italic
$draw->setFontStyle(Gmagick::STYLE_ITALIC);
  
// Annotate a text
$draw->annotate(50, 100, 'The Font style here is '
    . $draw->getFontStyle() . '.');
  
// Use of drawimage functeannotate
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>


Output:

Reference: https://www.php.net/manual/en/gmagickdraw.getfontstyle.php

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS