PHP | GmagickDraw settextencoding() function

The GmagickDraw::settextencoding() function is an inbuilt function in PHP which is used to set the code set used for text annotations. These code sets tell the computer how to interpret raw zeroes and ones into real characters. Usually, they produce the same text but use different code sets.

Syntax:

GmagickDraw GmagickDraw::settextencoding( string $encoding )

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



Return Value: This function returns GmagickDraw object on success.

Exceptions: This function throws GmagickDrawException on error.

Below given programs illustrate the GmagickDraw::settextencoding() function in PHP:
Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Set the encoding
$draw->settextencoding('utf-32');
  
// Get the encoding
$encoding = $draw->gettextencoding();
echo $encoding;
?>

chevron_right


Output:

utf-32

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// Create a new Gmagick object
$gmagick = new Gmagick('geeksforgeeks.png');
  
// Create a GmagickDraw object
$draw = new GmagickDraw();
  
// Draw rectangle for background
$draw->rectangle(-100, -1000, 800, 400);
  
// Set the fill color
$draw->setfillcolor('white');
  
// Set the font size
$draw->setfontsize(30);
  
// Set the stroke color
$draw->setstrokecolor('green');
  
// Set the encoding
$draw->settextencoding('utf-8');
  
// Create a rectangle
$draw->annotate(20, 110, 'This text is encoded using ' . $draw->gettextencoding());
  
// Use of drawimage function
$gmagick->drawImage($draw);
  
// Display the output image
header("Content-Type: image/png");
echo $gmagick->getImageBlob();
?>

chevron_right


Output:

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



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.