开发者

turning text into image - PHP/GD - save image

I'm using this script to simply create an image from text. What I would like to know is how to save the image instead of printing 开发者_JAVA技巧straight to browser;

// an email address in a string
     $string = $post[$key];

     // some variables to set
     $font  = 4;
     $width  = ImageFontWidth($font) * strlen($string);
     $height = ImageFontHeight($font);

     // lets begin by creating an image
     $im = @imagecreatetruecolor ($width,$height);

     //white background
     $background_color = imagecolorallocate ($im, 255, 255, 255);

     //black text
     $text_color = imagecolorallocate ($im, 0, 0, 0);

     // put it all together
     $image = imagestring ($im, $font, 0, 0,  $string, $text_color);

I know its probably just one line of code at the end but im not sure which GD function to use.

Any help would be much appreciated, Regards, Phil.

EDIT:

I have tried the following but just get a balnk black box;

 // an email address in a string
     $string = $post[$key];

     // some variables to set
     $font  = 4;
     $width  = ImageFontWidth($font) * strlen($string);
     $height = ImageFontHeight($font);

     // lets begin by creating an image
     $im = @imagecreatetruecolor ($width,$height);

     //white background
     $background_color = imagecolorallocate ($im, 255, 255, 255);

     //black text
     $text_color = imagecolorallocate ($im, 0, 0, 0);

     // put it all together
     imagestring ($im, $font, 0, 0,  $string, $text_color);

     imagepng($im, 'somefile.png');

       imagedestroy($im);


Pass a filename to the appropriate image-generating image*() function:

imagepng($image, 'somefile.png');


Look at here http://www.php.net/manual/en/function.imagepng.php


take a look at imagepng() (or imagegif, imagejpeg...) - if you add a filename as second parameter, the image is saved as file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜