How to convert Text to image using PHP

In this post, we are going to see how to change any Text to image using PHP. PHP comes with an image processing library called the GD library. This has many features like creating an image drawing a Text, color to the text,  stable diffusion inpainting etc.., there many of function the those are really easy to understand are writing programs.

GD library has to be installed in your Apache server to make this script work!.

When I submit a text input via an HTML form to the PHP code, then in PHP I invoke GD library functions to convert to text input into an image. I create image layers for putting the text and background. Then, I merged the layers and copy the required portion to show the final output image to the browser.

Here the full code:



body {
    width: 550px;
    font-family: Arial;
#submit {
    padding: 10px 40px;
    background: #586e75;
    border: #485c61 1px solid;
    color: #FFF;
    border-radius: 2px;
#form {
    background-color: lightblue;

.form-row {
    padding: 20px;
    border-top: #8aacb7 1px solid;

.input-field {
    background: #FFF;
    padding: 10px;
    margin-left: 15px;
    width: 250px;
    border-radius: 2px;
    border: #8aacb7 1px solid;

.button-row {
    padding: 10px 20px;
    border-top: #8aacb7 1px solid;

#validation-response {
    background: #fdc0c0;
    padding: 10px 20px;

Then, see the result:

Then, put the input filed.