943,194 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 8326
  • PHP RSS
Sep 22nd, 2008
0

Convert a string into an image?

Expand Post »
Does anyone know if there's a function in php that will allow me to convert a string into an image?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
neclark2 is offline Offline
14 posts
since Feb 2008
Sep 22nd, 2008
0

Re: Convert a string into an image?

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
Reputation Points: 96
Solved Threads: 124
Master Poster
Will Gresham is offline Offline
728 posts
since May 2008
Sep 22nd, 2008
0

Re: Convert a string into an image?

Click to Expand / Collapse  Quote originally posted by neclark2 ...
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);
?>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
amir_php is offline Offline
1 posts
since Sep 2008
Sep 23rd, 2008
0

Re: Convert a string into an image?

once refer these links:
http://www.rafaeldohms.com.br/2008/0...e-with-php/en/
http://www.developertutorials.com/tu...620/page1.html

or try this:
php Syntax (Toggle Plain Text)
  1. <?php
  2. $image = ImageCreateFromPNG("base.png");
  3. $color = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
  4. $colorShadow = imagecolorallocate($image, 0x66, 0x66, 0x66);
  5. $font = 'arial.ttf';
  6. $fontSize = "10";
  7. $fontRotation = "0";
  8. $str = "Example of GD in PHP. Date: " . date("m-j-Y g:i:s (a)");
  9.  
  10. /* Shadow */
  11. ImageTTFText($image, $fontSize, $fontRotation, 7, 22, $colorShadow, $font, $str);
  12.  
  13. /* Top Level */
  14. ImageTTFText($image, $fontSize, $fontRotation, 5, 20, $color, $font, $str);
  15.  
  16. header("Content-Type: image/PNG");
  17. ImagePng ($image);
  18. imagedestroy($image);
  19. ?>
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Jul 27th, 2011
0
Re: Convert a string into an 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,
Last edited by Ezzaral; Jul 27th, 2011 at 1:50 pm. Reason: Snipped email. Please keep it on site.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
samnang.nong is offline Offline
1 posts
since Jul 2011
Aug 1st, 2011
0
Re: Convert a string into an image?
Check if your PHP configuration has PNG Support enabled. Just create a php file with phpinfo():

PHP Syntax (Toggle Plain Text)
  1. <?php phpinfo();?>

and call the file from the browser. In the GD section you should see something like in the attachment. Bye
Attached Thumbnails
Click image for larger version

Name:	gd.png
Views:	75
Size:	47.0 KB
ID:	21843  
Reputation Points: 201
Solved Threads: 83
Posting Pro
cereal is online now Online
514 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Storing Date of Birth
Next Thread in PHP Forum Timeline: Google Map-Mysql





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC