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

Recommended Answers

All 5 Replies

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);
?>

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);
?>

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,

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 :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.