954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Convert a string into an image?

Does anyone know if there's a function in php that will allow me to convert a string into an image?

neclark2
Newbie Poster
14 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

The GD Library will alow you to add text to an image, the GD library can be obtained from http://www.libgd.org/Main_Page

Will Gresham
Master Poster
755 posts since May 2008
Reputation Points: 96
Solved Threads: 125
 
Does anyone know if there's a function in php that will allow me to convert a string into an image?

Draw a string horizontally (PHP 4, PHP 5)

bool imagestring ( resource image, int font, int x, int y, string string, int color )

<?php
// create a 100*30 image
$im = imagecreate(100, 30);

// white background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// write the string at the top left
imagestring($im, 5, 0, 0, "Hello world!", $textcolor);

// output the image
header("Content-type: image/png");
imagepng($im);
?>

amir_php
Newbie Poster
1 post since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

once refer these links:
http://www.rafaeldohms.com.br/2008/02/12/adding-text-to-images-in-real-time-with-php/en/
http://www.developertutorials.com/tutorials/php/adding-custom-text-to-image-050620/page1.html

or try this:

<?php
$image = ImageCreateFromPNG("base.png");
$color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
$font = 'arial.ttf';
$fontSize = "10";
$fontRotation = "0";
$str = "Example of GD in PHP.    Date: " . date("m-j-Y  g:i:s (a)");

/* Shadow */
ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str);

/* Top Level */
ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str);

header("Content-Type: image/PNG");
ImagePng ($image);
imagedestroy($image);
?>
Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

Hi,

i got the error message as below:

Fatal error: Call to undefined function ImageCreateFromPNG() in C:\wamp\www\str to img\test.php on line 2

regards,

samnang.nong
Newbie Poster
1 post since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

Check if your PHP configuration has PNG Support enabled. Just create a php file with phpinfo():

<?php phpinfo();?>


and call the file from the browser. In the GD section you should see something like in the attachment. Bye :)

Attachments gd.png 46.98KB
cereal
Master Poster
709 posts since Aug 2007
Reputation Points: 214
Solved Threads: 120
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You