Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

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:

index.php

style.css

body {
    width: 550px;
    font-family: Arial;
}
#submit {
    padding: 10px 40px;
    background: #586e75;
    border: #485c61 1px solid;
    color: #FFF;
    border-radius: 2px;
    cursor:pointer;
}
#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 {
    display:none;
    background: #fdc0c0;
    padding: 10px 20px;
}

Then, see the result:

Then, put the input filed.

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.