Jump to content

create text image using php


Nandini

Recommended Posts

Hi i want to create text image using php. Its all are working fine. But when i am trying to multi line text its not working. If i am use '\n' and '<br>' image displayed as it is \n and <br>. Here is my scripts. Can i anyone guide me.

 

<?
header("Content-type: image/png"); // Tell  the browser it's an image, not a .php file.

$text = 'Sample text\nSample text';

$number = strlen($text);  // Count the chars in the text.

$number = ($number*7)+9; // Times this by 7 and add 9 to make it look the right size.

$im = imagecreate($number, 24); // Create the basic size, $number x 24

$colour1 = imagecolorallocate($im, 0, 0, 0); // Background (RGB) black.

$colour2 = imagecolorallocate($im, 255, 255, 255); // Background white.

imagestring($im, 3, 5, 5,  $text, $colour2); // Add the text to the image.

imagepng($im); // Create and display the image.

imagedestroy($im); // Cast the image from the server (will cause lag eventually if you don't).

?>

 

 

Thanq

Link to comment
https://forums.phpfreaks.com/topic/125104-create-text-image-using-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.