1

「その他の記号と絵文字」ユニコード ブロックの下にある絵文字を描画する際に問題が発生しました。

コード例を次に示します。

<?php
    header('Content-Type: image/png');

    $im = imagecreatetruecolor(290, 60);

    $grey = imagecolorallocate($im, 200, 200, 200);
    $black = imagecolorallocate($im, 0, 0, 0);
    imagefilledrectangle($im, 0, 0, 289, 59, $grey);

    $font = 'seguisym.ttf';
    $font = realpath($font);

    //&#127744; is the unicode html entity for a cyclone. It is under 'Miscellaneous Symbols And Pictographs'.
    $text = "&#127744; is a cyclone!";
    imagettftext($im, 20, 0, 5, 22, $black, $font, $text);

    //&#9924; is the unicode html entity for a snowman. It is under 'Miscellaneous Symbols'.
    $text = "&#9924; is a snowman!";
    imagettftext($im, 20, 0, 5, 52, $black, $font, $text);

    imagepng($im);
    imagedestroy($im);
?>

出力は次のとおりです。

サイクロンとスノーマン

これは次のようになります。

サイクロンと雪だるま 後編

ご覧のとおり、これらの絵文字は両方とも異なる Unicode ブロックの下にあります。サイクロンは「Miscellaneous Symbols And Pictographs」の下にあり、実際のキャラクターの代わりに HTML エンティティが描画されますが、雪だるまは「Miscellaneous Symbols」の下にあり、正しく描画されます。使用しているフォントに両方の文字が含まれていることを再確認しました。

明確にするために、HTML エンティティではなく、実際の文字を描画したいと考えています。

UTF8 としてレンダリングされた同じ文字:

サイクロンと雪だるま、パート III

4

1 に答える 1

0

Abigail TTF でこれと同じ種類の問題に遭遇しました。いくつかの調査の後、私はこのリンクを見つけました

https://bugs.php.net/bug.php?id=17955

このサンプルスクリプトが含まれていました:

<?php
$str = "this is a test";
$str = iconv("UCS-2", "UTF-8", preg_replace("/(.)/","\xf0\$1", $str));

$fsize = 32;
$ffile= "C:/wamp/www/gm/fonts/Aztec/101_Aztec SymbolZ.ttf";

$size = ImageTTFBBox($fsize, 0, $ffile, $str);

$txt_width = ($size[2] - $size[0]);
$txt_height = ($size[1] - $size[7]);

$im_width = $txt_width * 1.5;
$im_height = $txt_height * 1.5;

$im = ImageCreateTrueColor($im_width, $im_height);
$black = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);

$txt_x = ($im_width - $txt_width) / 2;
$txt_y = ($im_height - $txt_height) / 2 + $txt_height;

ImageFilledRectangle($im, 0, 0, $im_width, $im_height, $white);
imagecolortransparent( $im, $white );
ImageTTFText($im, $fsize, 0, $txt_x, $txt_y, $black, $ffile, $str);

Imagegif($im, "./test.gif");
ImageDestroy($im);
?>

彼らの答え: 文字列を正しく Unicdoe に変換する必要があります。これにより、Abigail フォントが正しく表示されるようになりました。残念ながら、非標準の TTF ファイルを適切に表示する方法をまだ検討中です。しかし、実際のフォント (サイクロン画像など) をどこに配置するかが問題だと思います。

もう1つのイライラする要因は、GDが四角を入れたり、文字を空白のままにしたりすることです. これは WIDTH=0 および HEIGHT=0 として返されるのに対し、正方形はさまざまなサイズで返される可能性があるため、常に空白文字を指定することを本当に望んでいます。GD が常にサイズのない空白文字を返すように標準化されている場合は、それを探すだけです。それ以外の場合 - 正方形が返されたことを確認するには、フープをジャンプする必要があります。

これが役立つことを願っています!:-)

于 2015-12-07T05:12:29.377 に答える