Friday, October 17, 2025
HomeLanguagesPHP | ImagickDraw setTextKerning() Function

PHP | ImagickDraw setTextKerning() Function

The ImagickDraw::setTextKerning() function is an inbuilt function in PHP which is used to set the text kerning which defines the spacing between the text.

Syntax:

bool ImagickDraw::setTextKerning( float $kerning )

Parameters: This function accepts a single parameter $kerning which holds the text kerning.

Return Value: This function returns TRUE on success.

Exceptions: This function throws ImagickException on error.

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

Program 1:




<?php
  
// Create a new ImagickDraw object
$draw = new ImagickDraw();
  
// Set the text Kerning
$draw->setTextKerning(10);
  
// Get the text Kerning
$textKerning = $draw->getTextKerning();
echo $textKerning;
?>


Output:

10

Program 2:




<?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('red');
  
// Set the text kerning
$draw->setTextKerning(30);
  
// Set the font size
$draw->setFontSize(50);
  
// Annotate a text
$draw->annotation(50, 200, 'neveropen');
  
// 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.settextkerning.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS