Adding custom text over image or pictures is a good way to declare copyrights or give a simple title information to that graphical image or picture without editing the image itself. PHP has made it very easy to add custom text over image or picture by using some basic functions from PHP GD.
Complete code for adding text over image
Customizing the text for your usage:
- Change the
$imgPath
to image path you want to add text over it. - In “
$color = imagecolorallocate[$image, 255 , 255, 255]
” change the color code to color that suites with the image. for example, if the image background is white then change [255, 255, 255] to [0, 0, 0] which is code for black color. $string
is the text will be added over the image.$fontSize
is the font size number.$x
is the text margin from left.$y
is the text margin from top
Resources:
- imagecreatefromjpeg [Create a new image from file or URL and returns an image identifier representing the image obtained from the given filename].
- imagecolorallocate [Allocate a color for an image and returns a color identifier representing the color composed of the given RGB components].
- imagestring [Draw a string horizontally]
- imagejpeg [Output image to browser or file]
The image used in this article is taken from //vectorialpx.net
As always, any comments or suggestion would be really appreciated.
The post Write Text Over Image or Picture with PHP appeared first on Recent Solutions.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.
Last Updated : Apr 15, 2022
IN - PHP PHP GD
In this tutorial we will show you how to add text to images using PHP GD library.The text can be any text like your name, web address, email or your number.You may also like add watermark to an image using PHP.
Join With 27,000+ Members In Our Google Group & Get Latest Tutorials
Get our latest tutorials, How-To guides on web development every day right into your inbox.
To Add Text To Image It Takes Only One Step:-
- Make a PHP file and define scripting
Step 1. Make a PHP file and define scripting
We make a PHP file and save it with a name text_to_image.php
In this step we first set the image header to return image after processing.Then we load the image from directory and create that image using imagecreatefromjpeg[] function then we allocate the color.
We use white color in text so we use RGB value of white you can use any color RGB value, then we specify font path it is very important to add font path because without using font your text will not be visible you can use any font for your text.
Then we set the text and use imagettftext[] function to add text to images you can also customise the size, angle and position of the text as per your need.You may also like display text over image.
Thats all, this is how to add text on images using PHP and php gd library.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.
Latest Tutorials
- Create Animated Skill Bar Using jQuery, HTML And CSS
- Simple And Best Responsive Web Design Using CSS Part 2
- Show Button On Hover Using HTML And CSS
- Material Design Login Form Using jQuery And CSS
- Animated Progress Bar Using jQuery And CSS
- Dynamic Drop Down Menu Using jQuery, Ajax, PHP And MySQL
- Get Website Statistics Using PHP, jQuery And MySQL
- HTML5 Login And Signup Form With Animation Using jQuery
- Facebook Style Homepage Design Using HTML And CSS
- View Webpage In Fullscreen Using jQuery