Add text to images with PHP
In this tutorial i will show you how you can add text using GD Library here is a very simple code to do that.
[wpdm_file id=8]
Write Text on image
In this file we use an image and write some text when we run that code it will write text on that image where ever you want to add in the image X and Y coordinates required.
<?php header ("Content-type: image/jpeg"); $string = "This is phpGang.com"; $font = 4; $width = imagefontwidth($font) * strlen($string) ; $height = imagefontheight($font) ; $im = imagecreatefromjpeg("gang.jpg"); $x = imagesx($im) - $width ; $y = imagesy($im) - $height; $backgroundColor = imagecolorallocate ($im, 255, 255, 255); $textColor = imagecolorallocate ($im, 0, 0,0); imagestring ($im, $font, $x, $y, $string, $textColor); imagejpeg($im); ?>
After running this code you will get image like this.
Tutorial Categories:
hello.
how can i replace the background image (gang.jpg) with a database images which will pick them randomly?
i mean.. i want to replace gang.jpg with $random_images_from_a_path
thank you
Replace name of image like this.
$im = imagecreatefromjpeg($random_images_from_a_path);
i need some help in php can anybody help me please