Saturday, June 13, 2026
HomeLanguagesPHP | GmagickDraw setfontweight() Function

PHP | GmagickDraw setfontweight() Function

The GmagickDraw::setfontweight() function is an inbuilt function in PHP that is used to set the font weight. 

Syntax:

 public GmagickDraw::setfontweight( $font_weight ) : GmagickDraw

Parameters: This function accepts a single parameter $font_weight which is used to hold the value of font-weight as an integer type. 

Return Value: This function returns the GmagickDraw object on success. The below programs illustrate the GmagickDraw::setfontweight() 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 Weight
$draw->setFontWeight(200);
 
// Set the font size
$draw->setFontSize(40);
 
// Set the font family
$draw->setFontFamily('Ubuntu-Mono');
 
// Set the text to be added
$draw->annotation(30, 170, "GeeksForGeeks");
 
// Set the image filled color
$draw->setFilledColor('green');
 
// Set the Font Stretch
$draw->setFontStretch(3);
 
// Set the font size
$draw->setFontSize(30);
 
// Set the font family
$draw->setFontFamily('Open-Sans-Light-Italic');
 
// Set the text to be added
$draw->annotation(30, 250, "Font-Weight : 200");
 
// Create new gmagick object   
$gmagick = new Gmagick();
 
// Set the image dimension
$gmagick->newImage(350, 300, 'white');
 
// Set the image fromat
$gmagick->setImageFormat("png");
 
// Draw the image
$gmagick->drawImage($draw);
header("Content-Type: image/png");
 
// Display the image
echo $gmagick->getImageBlob();
?>


Output: 

setFontWeight

Program 2: 

php




<?php
 
// Create an GmagickDraw object
$draw = new GmagickDraw();
 
// Set the image filled color
$draw->setFilledColor('Green');
 
// Set the font size
$draw->setFontSize(30);
 
// Set the Font Weight
$draw->setFontWeight(400);
 
// Set the font family
$draw->setFontFamily('Ani');
 
// Set the text to be added
$draw->annotation(30, 40, "GeeksForGeeks");
 
// Create new Gmagick object   
$gmagick= new Gmagick();
 
// Set the image dimension
$gmagick->newImage(250, 70, '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: 

setFontWeight

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

RELATED ARTICLES

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS