如果想利用PHP在图片上生成文字,就必须在php.ini里面将gd库开启,php在图片上生成文字代码如下:
-
- header("content-type: image/png");
-
- $im=@imagecreate(150,50) or die("cannot initialize new gd image stream");
-
- $background_color=imagecolorallocate($im,255,255,255);
-
- $text_color=imagecolorallocate($im,233,14,91);
-
- imagestring($im,3,5,5,"hello world",$text_color);
-
- imagepng($im);
-
- imagedestroy($im);
-
-
-
-
-
-
-
- $filename='1.jpg';
-
- $percent=0.5;
-
- header('content-type: image/jpeg');
-
- list($width,$height)=getimagesize($filename);
- $newwidth=$width * $percent;
- $newheight=$height * $percent;
-
- $thumb=imagecreatetruecolor($newwidth,$newheight);
- $source=imagecreatefromjpeg($filename);
-
- imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
-
- imagejpeg($thumb);
-
-
-
-
-
-
-
- $data='ivborw0kggoaaaansuheugaaabwaaaascamaaab/2u7waaaabl'.
- 'bmveuaaad///+l2z/daaaasuleqvr4xqwquqoaiaxc2/0vxzdr'.
- 'ex4ijtrkb7lobnustxsb0jixiamssqnwlsv+wulf4avk9flq2r'.
- '8a5hse35q3eo2xp1a1wqkzsgetvdtkdqaaaabjru5erkjggg==';
-
- $data=base64_decode($data);
-
- $im=imagecreatefromstring($data);
- if($im!== false)
- {
-
- header('content-type: image/png');
- imagepng($im);
- }
- else
- {
-
- echo 'an error occured.';
- }
-
-
-
- header("content-type: image/png");
-
- $im=@imagecreate(100,50) or die("cannot initialize new gd image stream");
-
- $background_color=imagecolorallocate($im,255,255,255);
-
- $text_color=imagecolorallocate($im,233,14,91);
-
- imagestring($im,1,5,5,"a simple text string",$text_color);
-
- imagepng($im);
-
- imagedestroy($im);
-
-
-
-
|