Thursday, September 4, 2025
HomeLanguagesPHP | GmagickDraw setfontstyle() Function

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 value of font style as integer type. 

STYLE constants: A list of style constants is given below:

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

Return Value: This function returns the GmagickDraw object on success. The below programs illustrate the GmagickDraw::setfontstyle() function in PHP.

Program 1: 

php




<?php
 
// Create an GmagickDraw object
$draw = new GmagickDraw();
 
// Set the image filled color
$draw->setFilledColor('red');
 
// Set the Font Size
$draw->setFontSize(40);
 
// Set the Font Style
$draw->setfontstyle(\Gmagick::STYLE_OBLIQUE);
 
// Set the text to be added
$draw->annotation(30, 170, "GeeksForGeeks");
 
// Set the image filled color
$draw->setFilledColor('green');
 
// Set the font size
$draw->setFontSize(30);
 
// Set the text to be added
$draw->annotation(30, 250, "Oblique Style");
 
// Create new Gmagick object    
$gmagick= new Gmagick();
 
// Set the image dimension
$gmagick->newImage(350, 300, '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: 

setFontStyle

Program 2: 

php




<?php
 
// Create an GmagickDraw object
$draw = new GmagickDraw();
 
// Set the image filled color
$draw->setFilledColor('black');
 
// Set the font size
$draw->setFontSize(30);
 
// Set Font Style
$draw->setfontstyle(\Gmagick::STYLE_ITALIC);
 
// Set the text to be added
$draw->annotation(30, 170, "GeeksForGeeks");
 
// Set the image filled color
$draw->setFilledColor('blue');
 
// Set the font size
$draw->setFontSize(25);
 
// Set the text to be added
$draw->annotation(30, 250, "Italic Style");
 
// Create new Gmagick object    
$gmagick= new Gmagick();
 
// Set the image dimension
$gmagick->newImage(350, 300, '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: 

setFontStyle

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

RELATED ARTICLES

Most Popular

Dominic
32262 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6626 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11857 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6696 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS