The GmagickDraw::gettextencoding() function is an inbuilt function in PHP which is used to get 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:
string GmagickDraw::gettextencoding( void )
Parameters: This function doesn’t accept any parameters.
Return Value: This function returns a string value containing the text encoding used.
Exceptions: This function throws GmagickDrawException on error.
Below given programs illustrate the GmagickDraw::gettextencoding() function in PHP:
Program 1:
<?php // Create a new GmagickDraw object $draw = new GmagickDraw(); // Get the text encoding $textEncoding = $draw->gettextencoding(); echo $textEncoding; ?> |
Output:
// Empty string which is the default value
Program 2:
<?php // Create a new GmagickDraw object $draw = new GmagickDraw(); // Set the text encoding $draw->settextencoding('utf-8'); // Get the text encoding $textEncoding = $draw->gettextencoding(); echo $textEncoding; ?> |
Output:
utf-8
Used Image:

Program 3:
<?php // Create a new Gmagick object $gmagick = new Gmagick('geeksforgeeks.png'); // Create a GmagickDraw object $draw = new GmagickDraw(); // Set the color $draw->setFillColor('#0E0E0E'); // Draw rectangle for background $draw->rectangle(-10, -10, 800, 400); // Set the font size $draw->setFontSize(40); // Set the fill color $draw->setfillcolor('white'); // Set the text encoding $draw->settextencoding('UTF-8'); // Annotate a text $draw->annotate(50, 50, 'This line is encoded with ' . $draw->getTextEncoding()); // Set the text encoding $draw->settextencoding('UTF-32'); // Annotate a text $draw->annotate(50, 100, 'This line is encoded with ' . $draw->getTextEncoding()); // 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.gettextencoding.php
Recommended Posts:
- PHP | ImagickDraw getTextEncoding() Function
- PHP | GmagickDraw rectangle() Function
- PHP | GmagickDraw setstrokewidth() Function
- PHP | GmagickDraw setfontstyle() Function
- PHP | GmagickDraw setfontweight() Function
- PHP | GmagickDraw settextdecoration() Function
- PHP | GmagickDraw setfillopacity() Function
- PHP | GmagickDraw setstrokecolor() Function
- PHP | GmagickDraw setstrokeopacity() Function
- PHP | GmagickDraw scale() Function
- PHP | GmagickDraw roundrectangle() Function
- PHP | GmagickDraw point() Function
- PHP | GmagickDraw line() Function
- PHP | GmagickDraw setfontsize() Function
- PHP | GmagickDraw getfontsize() Function
- PHP | GmagickDraw getstrokeopacity() Function
- PHP | GmagickDraw getstrokewidth() Function
- PHP | GmagickDraw getfillcolor() function
- PHP | GmagickDraw ellipse() function
- PHP | GmagickDraw bezier() Function
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.

