您好,我一直在开发一个脚本,该脚本可以从以下文本生成图像:
<?php
ini_set("default_charset", "UTF-8");
mb_internal_encoding("UTF-8");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$font ='Amperzand.ttf';
$fuente_tamano = 25;
$texto="Es irónico que el amor sea lo más bonito y lo más letal.";
utf8_encode($texto);
$im = imagecreate(400,400);
$fondo=imagecolorallocate ($im, rand(0,255), rand(0,100), rand(0,255));
//Colores
$blanco = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$gris=imagecolorallocate ($im, 160, 160,160);
$negro=imagecolorallocate ($im, 0, 0, 0);
$colorGris = imagecolorallocate($im, 200, 200, 200);
$colorAzul = imagecolorallocate($im, 0, 0, 255);
$lines1 = explode('|', wordwrap(utf8_encode($texto), 28, '|'));
$y=50;
foreach ($lines1 as $line1) {
{
$line1=trim($line1);
//$line1 = str_pad($line1, 30,"0", STR_PAD_BOTH);
$marco= ImageTTFBBox ($fuente_tamano, 0, $font, $line1);
$x = (400 - ($marco[2]-$marco[0])) / 2;
$y += 30;
// El texto negro para que lo usaremos como borde
imagettftext($im, $fuente_tamano, 0, $x + 2 , $y + 1 , $negro, $font, $line1);
imagettftext($im,$fuente_tamano, 0, $x - 2 , $y - 1 , $negro, $font, $line1);
// El texto blanco
imagettftext($im,$fuente_tamano, 0, $x , $y, $blanco, $font, $line1);
}
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
?>
你怎么能看到变量?
$文本
包含带有重音的短语,当传递给图像时不完整且有错误。
我想知道是否有任何功能可以解决这个问题以及如何在这段代码中实现它。
我试过utf8_decode();
了,但我无法解决
以这种方式使用给定的使用utf8_encode();
和离开脚本的解决方案,但问题仍然存在,我希望有人能告诉我哪里错了。
您可以尝试将其添加到您的 PHP 文件中:
同样,您必须更正以下行:
A:
正如他们所提到的,使用utf8_decode
干杯
我希望您可以使用
mb_convert_encoding()
,preg_replace()
和正则表达式 (regex) 来使用此功能。(也许有更好的正则表达式,但我知道的不多,所以我希望它对你有用)不要使用
utf8_decode();
使用utf8_encode();
,因为您正在将其“解码”为 utf8,而您需要做的是“编码”它。