Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.94k stars 1.5k forks source link

The text method different output the Chinese/Japanese string which use the gd/imagic. #1339

Closed hetao29 closed 6 months ago

hetao29 commented 6 months ago

Describe the bug gd output chinese string need to unicode imagic not need

Code Example

$manger = Intervention\Image\ImageManager::imagick();
$manger->text("中国");
$manger = Intervention\Image\ImageManager::gd();
$manger->text("中国");
$manger->text(toUnicode("中国"));

function toUnicode($string){
        $str = mb_convert_encoding($string, 'UCS-2', 'UTF-8');
        $arrstr = str_split($str, 2);
        $unistr = '';
        foreach ($arrstr as $n) {
            $dec = hexdec(bin2hex($n));
            $unistr .= '&#' . $dec . ';';
        }
        return $unistr;
    }

Expected behavior do not toUnicode when use the gd.

olivervogel commented 6 months ago

I can not reproduce this issue. Please make sure that you are using the latest version of the GD and/or Imagick library and a font that supports the corresponding characters.

$image = ImageManager::withDriver($driver)
    ->create(300, 300)
    ->fill('fff');

$image->text("中国", 150, 150, function ($font) {
    $font->filename('ArialUnicodeMS.ttf');
    $font->size(70);
    $font->color('000');
    $font->align('center');
    $font->valign('middle');
});

PHP Version: 8.3.4 OS: MacOS Intervention Image Version: 3.6.2 Imagick 3.7.0 / ImageMagick 7.1.1-27 Q16-HDRI aarch64 GD 2.3.3

Result Image (GD)

gd

Result Image (Imagick)

imagick

hetao29 commented 6 months ago
$fonts = "/fonts/msyh.ttf";
$mgr = Intervention\Image\ImageManager::imagick();
//$mgr = Intervention\Image\ImageManager::gd();
$img = $mgr->create(400,300);
$text="我是中国人";
$txt_color="rgba(121,143,85,1)";
$img->text($text,50,100,function (Intervention\Image\Typography\FontFactory $font) use ($fonts,$txt_color){
    $font->file($fonts);
    $font->size(30);
    $font->color($txt_color);
    $font->align('left');
    $font->valign('bottom');
});

This image is build by imagick: image This image is build by gd: image

PHP Version 8.3.6 OS: System Linux 5.15.0-105-generic #115-Ubuntu SMP Mon Apr 15 09:52:04 UTC 2024 x86_64 Configure Command: './configure' '--prefix=/data/php8' '--with-ldap' '--with-zlib' '--with-gettext' '--enable-intl' '--enable-exif' '--with-mysqli' '--enable-fpm' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-curl' '--enable-ftp' '--enable-gd' '--with-freetype' '--with-jpeg' '--with-webp' '--enable-gd-jis-conv' '--with-imap' '--enable-mbstring' '--enable-pcntl' '--enable-mysqlnd' '--with-pdo-mysql' '--enable-sockets' '--with-zip' '--enable-bcmath' '--with-kerberos' '--with-imap-ssl' '--with-openssl' '--without-pdo-sqlite' '--without-sqlite3' '--enable-calendar' '--enable-shmop' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm'

Php Info:

image

GD info:

image

Imageic Info:

image

Intervention Image Version: 3.6.2

olivervogel commented 6 months ago

Works as well. Maybe upgrading to a newer GD version helps.

GD

gd

Imagick

imagick