Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hetao29 opened this issue Apr 29, 2024 · 3 comments

Comments

@hetao29
Copy link

hetao29 commented Apr 29, 2024

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
Copy link
Member

olivervogel commented Apr 29, 2024

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
Copy link
Author

hetao29 commented Apr 30, 2024

$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
Copy link
Member

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

GD

gd

Imagick

imagick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants