PHP | ImagickDraw setFont() Function
The ImagickDraw::setFont() function is an inbuilt function in PHP which is used to set the fully-specified font to use when annotating with text.
Syntax:
bool ImagickDraw::setFont( $font_name )
Parameters: This function accepts a single parameter $font_name which is used to hold the value of font name as string.
Return Value: This function returns True on success.
Below programs illustrates the ImagickDraw::setFont() function in PHP:
Program 1:
<?php // Create an ImagickDraw object. $draw = new ImagickDraw(); // Set the fill color $draw->setFillColor('green'); // Set the Font Size $draw->setFontSize(40); // Set the Font Style $draw->setFont("./font/IndieFlower.ttf"); // Set the text to be added $draw->annotation(50, 50, "GeeksForGeeks"); // Set the Font Style $draw->setFont("./font/DancingScript-Regular.ttf"); // Set the text to be added $draw->annotation(10, 100, "A Computer Science Portal For Geeks!"); // Set the Font Style $draw->setFont("./font/NanumGothic-Regular.ttf"); // Set the text to be added $draw->annotation(50, 150, "@sarthak_ishu11"); // Create new Imagick object $imagick = new Imagick(); // Set the image dimension $imagick->newImage(560, 200, 'white'); // Set the image format $imagick->setImageFormat("png"); // Draw the image $imagick->drawImage($draw); header("Content-Type: image/png"); // Display the image echo $imagick->getImageBlob(); ?> |
Output:

Program 2:
<?php // Create an ImagickDraw object $draw = new ImagickDraw(); // Set the Font Size $draw->setFontSize(40); // Set the image filled color $draw->setFillColor('green'); // Draw the rectangle $draw->rectangle(30, 100, 300, 300); // Set the image filled color $draw->setFillColor('black'); // Set the font style $draw->setFont("./font/IndieFlower.ttf"); // Set the text to be added $draw->annotation(35, 280, "GeeksForGeeks"); // Create new Imagick object $imagick = new Imagick(); // Set the image dimensions $imagick->newImage(330, 330, 'white'); // Set the image format $imagick->setImageFormat("png"); // Draw the image $imagick->drawImage($draw); header("Content-Type: image/png"); // Display the image echo $imagick->getImageBlob(); ?> |
Output:

Reference: http://php.net/manual/en/imagickdraw.setfont.php
Recommended Posts:
- PHP | ImagickDraw arc() Function
- PHP | ImagickDraw translate() Function
- PHP | ImagickDraw line() Function
- PHP | ImagickDraw circle() Function
- PHP | ImagickDraw setStrokeOpacity() Function
- PHP | ImagickDraw setStrokeWidth() Function
- PHP | ImagickDraw rectangle() Function
- PHP | ImagickDraw skewX() Function
- PHP | ImagickDraw bezier() Function
- PHP | ImagickDraw setFontSize() Function
- PHP | ImagickDraw setFontWeight() Function
- PHP | ImagickDraw setStrokeMiterLimit() Function
- PHP | ImagickDraw setFillOpacity() Function
- PHP | ImagickDraw setFontFamily() Function
- PHP | ImagickDraw setGravity() 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.



