Home Backend Development PHP Tutorial 用imagettftext在图片上输入字符,无法在浏览器中生成图片,该怎么解决

用imagettftext在图片上输入字符,无法在浏览器中生成图片,该怎么解决

Jun 13, 2016 pm 01:46 PM
button imagepng imagettftext png

用imagettftext在图片上输入字符,无法在浏览器中生成图片
我imagettftext函数在图片上写入汉字字符串,可是却无法在浏览器中输出图片,使用imagepng($im,'x.png');可以将图片输出,但是如果直接输出到浏览器却不行,求高手调教啊。以下我的代码

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php Header('Content-type: image/png');
putenv('GDFONTPATH=C:\WINDOWS\Fonts');
$button_text='Button按钮';
$button_text=$button_text.rand(30, 50);
$im=imagecreatetruecolor(400, 200);
$black=imagecolorallocate($im, 0, 0, 0);
$white=imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $black);
imagettftext($im,30,30, 0,150, $white,'MSYH.TTF', $button_text);
imagepng($im);//使用imagepng($im,'x.png');可以生成x.png,图片也有文字。
imagedestroy($im);
?>

Copy after login


------解决方案--------------------
探讨

引用:

引用:

没有任何错误提示啊,浏览器一片空白,不过如果用ie浏览器的话就出现一些乱码。我尝试用imagestring替代imagettftext就可以正常输出了,前提是我要去掉中文字符……


imagestring不支持中文汉字。只能yong imagettftext.如果是乱码,证明是图片生成前可能有输……

------解决方案--------------------
探讨
我imagettftext函数在图片上写入汉字字符串,可是却无法在浏览器中输出图片,使用使用imagepng($im,'x.png');可以生成x.png,图片也有文字。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to convert PNG to JPG on Windows 11 How to convert PNG to JPG on Windows 11 May 12, 2023 pm 03:55 PM

How to convert PNG to JPG on Windows 11

How to set button size and color in html How to set button size and color in html Mar 05, 2021 pm 05:16 PM

How to set button size and color in html

How to rename the extension of all files within a folder, including subfolders How to rename the extension of all files within a folder, including subfolders Apr 14, 2023 pm 12:22 PM

How to rename the extension of all files within a folder, including subfolders

What format is png? What format is png? Dec 10, 2020 pm 04:16 PM

What format is png?

What is the format of png files? What is the format of png files? Feb 19, 2024 pm 08:32 PM

What is the format of png files?

Detailed explanation of PHP chart generation function: chart generation guide for gd library, imagepng, imagestring and other functions Detailed explanation of PHP chart generation function: chart generation guide for gd library, imagepng, imagestring and other functions Nov 18, 2023 pm 04:56 PM

Detailed explanation of PHP chart generation function: chart generation guide for gd library, imagepng, imagestring and other functions

Which one is clearer, jpeg or png? Which one is clearer, jpeg or png? Mar 17, 2023 am 10:43 AM

Which one is clearer, jpeg or png?

How to make pictures into png How to make pictures into png Jan 19, 2021 am 09:14 AM

How to make pictures into png

See all articles