Does PHP imagemagick support with Unicode?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Does PHP imagemagick support with Unicode?

Post by hengsopheak »

I'm using PHP imageMagick by enable php extention (http://php.net/manual/en/book.imagick.php) then I try to used below method to insert the Khmer Unicode characters to that images by using http://camvgo.com/image/fonts/Kh-Siemreap.ttf ​ font but it is not correct



$strokeColor = "#000";
$fillColor = "red";
$backgroundColor = "#001";
$draw = new \ImagickDraw();


$text = "ប្រទេសកម្ពុជា";
$draw->setTextEncoding("UTF-8");

$draw->setFont(public_path('/image/fonts/KhmerOSMoul.ttf'));
$draw->setStrokeColor($strokeColor);
$draw->setFillColor($fillColor);
$draw->setStrokeWidth(1);
$draw->setFontSize(36);

$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 75, $text);
$draw->setTextAlignment(\Imagick::ALIGN_CENTER);
$draw->annotation(250, 150, "ប្រទេសកម្ពុជា");
$draw->setTextAlignment(\Imagick::ALIGN_RIGHT);
$draw->annotation(250, 225, "ប្រទេសកម្ពុជា");
$draw->line(250, 0, 250, 500);

$imagick = new \Imagick();
$imagick->newImage(500, 500, $backgroundColor);
$imagick->setImageFormat("png");
$imagick->drawImage($draw);
$imagick->setImageFormat('png');

header("Content-Type: image/png");
echo "<img src='data:image/jpg;base64,".base64_encode($imagick->getImageBlob())."' />";

Result

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does PHP imagemagick support with Unicode?

Post by fmw42 »

Have you created your file in a UTF-8 compatible text editor? If so, then perhaps your font does not support UTF-8 characters. To test, does it work in a terminal window in command line IM?

This command only shows me question marks for the characters. So I am not sure it is UTF-8 compliant. I simply typed in a UTF-8 compliant test editor holding the control key and typing abcdefg.

Code: Select all

convert -size 500x -font /Library/fonts/Kh-Siemreap.ttf label:"å∫ç∂´ƒ©" tmp.png
I think you have to type the characters and not put in the codes for the characters. Nevertheless, it does not work for me. And as you can see the characters are not the correct ones.

Whereas this works fine:

Code: Select all

convert -size 500x -font /Library/fonts/arial.ttf label:"å∫ç∂´ƒ©" tmp.png
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

I've tested it too on the magick commen-line and result is the same, However this font is work properly with Microsoft office all version and adobe all version and another application too. Oh,Moreover I have download the font from https://fonts.google.com/specimen/Siemr ... hum|Taprom googles.and now I'm trying contact to Font creator.
Last edited by hengsopheak on 2017-03-21T21:58:06-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does PHP imagemagick support with Unicode?

Post by fmw42 »

I do not know Microsoft Word (2007) that well regarding Unicode characters, but I could not get it to type high ascii characters without switching to times new roman. I am not sure you can copy from Word and paste into IM command line.
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

Dear Magick,
God not please me now I'm trying hard to find the solution but still stuck with this cause
I have to contact the font author that said let me try with my code is anything wrong with my configuration that said their font if work all application event Operating system.
now I decided to create videos https://youtu.be/oyjp-gveYaA and keep asking with another forum http://stackoverflow.com/questions/4286 ... ion-images and facebook group https://www.facebook.com/groups/2204685 ... 863335681/
Now try to research some another tutorial because I believe PHP ImageMagick can do this task.

Font

https://github.com/osify/cambodianfonts ... toshop-CS3


Thanks for your help
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Does PHP imagemagick support with Unicode?

Post by snibgo »

I suggest you try "pango:" instead of "label:".
snibgo's IM pages: im.snibgo.com
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

Dear Snibgo,

I want to ask you if pango work how about PHP script? I'm try to find a solution to use PHP for sending the command-line for PHP application (laravel)
on Ubunut 14. Should I got an example?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Does PHP imagemagick support with Unicode?

Post by snibgo »

Sorry, I don't use Imagick or PHP. An exec() command may be the easiest solution.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Does PHP imagemagick support with Unicode?

Post by fmw42 »

I doubt that Imagick supports pango. Nevertheless, I typed high ascii characters using your font and did not get the characters that you want using:

Code: Select all

convert -size 500x -font /Library/fonts/Kh-Siemreap.ttf pango:"å∫ç∂´ƒ©" tmp.png

I do not know how to get the characters you want from that font. I cannot even get them in Microsoft Word. You need to go to the developer of the font and find out how to specify those characters from simply typing in a Unicode (UTF-8) compliant text editor. My text editor which is Unicode UTF-8 compliant won't produce those characters either by typing with the option key along with other normal keys.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Does PHP imagemagick support with Unicode?

Post by snibgo »

After installing the font, Pango seems to work for me at the command line.

Code: Select all

convert -size 500x -font "Kh Siemreap" -pointsize 50 pango:@siemr.txt siemrp.png
siemr.txt is encoded as UTF-8, without the usual (for Windows) BOM at the start. I've uploaded it to http://snibgo.com/imforums/siemr.txt

The output is:
Image
snibgo's IM pages: im.snibgo.com
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

I'm trying with Ubuntu14.6 and Version: ImageMagick 6.7.7-10 2017-03-14 Q16
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

On the configuration
I have edit on Configure name
1: I added --with-pango


After configured I try to below commend-line as below.

convert -font /public/image/fonts/Kh-Siemreap.ttf -pointsize 30 pango:" ហត់ខ្លាំងណាស់ " mincho2_test55.png

Result

|17||17||17||17||17||17||17||17||17||17|
|85|and another character with numbers

So now I try to find any configuration with freetype or another option.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuremap [
<!ELEMENT configuremap (configure)+>
<!ELEMENT configure (#PCDATA)>
<!ATTLIST configure name CDATA #REQUIRED>
<!ATTLIST configure value CDATA #REQUIRED>
]>
<configuremap>
<configure name="NAME" value="ImageMagick"/>
<configure name="VERSION" value="6.7.7"/>
<configure name="LIB_VERSION" value="0x677"/>
<configure name="LIB_VERSION_NUMBER" value="6,7,7,10"/>
<configure name="SVN_REVISION" value="8535" />
<configure name="RELEASE_DATE" value="2017-03-14"/>

<configure name="CONFIGURE" value="./configure '--disable-silent-rules' '--prefix=/usr' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--sysconfdir=/etc' '--mand$
-Werror=format-security' 'CPPFLAGS=-D_FORTIFY_SOURCE=2' 'CXXFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security'
'FFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4' 'GCJFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4' 'LDFLAGS=-Wl,-Bsymbolic-functions
-Wl,-z,relro' '--with-modules' '--with-gs-font-dir=/usr/share/fonts/type1/gsfonts' '--with-magick-plus-plus' '--with-djvu' '--with-wmf' '--without-gvc'
'--with-pango' '--enable-shared' '--without-dps' '--without-fpx' '--with-perl-options=INSTALLDIRS=vendor' '--x-includes=/usr/include/X11'
'--x-libraries=/usr/lib/X11'"/>


<configure name="PREFIX" value="/usr"/>
<configure name="EXEC-PREFIX" value="/usr"/>
<configure name="INCLUDE_PATH" value="/usr/include/ImageMagick"/>
<configure name="CONFIGURE_PATH" value="/etc/ImageMagick/"/>
<configure name="SHARE_PATH" value="/usr/share/ImageMagick-6.7.7"/>
<configure name="DOCUMENTATION_PATH" value="/usr/share/doc/ImageMagick-6.7.7"/>
<configure name="EXECUTABLE_PATH" value="/usr/bin"/>
<configure name="LIBRARY_PATH" value="/usr/lib/x86_64-linux-gnu/ImageMagick-6.7.7"/>
<configure name="CODER_PATH" value="/usr/lib/x86_64-linux-gnu/ImageMagick-6.7.7/modules-Q16/coders"/>
<configure name="FILTER_PATH" value="/usr/lib/x86_64-linux-gnu/ImageMagick-6.7.7/modules-Q16/filters"/>
<configure name="CC" value="gcc -std=gnu99 -std=gnu99"/>
<configure name="CFLAGS" value="-I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -fopenmp -g$
<configure name="CPPFLAGS" value="-I/usr/include/ImageMagick"/>
<configure name="PCFLAGS" value="-fopenmp"/>
<configure name="DEFS" value="-DHAVE_CONFIG_H"/>
<configure name="LDFLAGS" value="-L/usr/lib/x86_64-linux-gnu -Wl,-Bsymbolic-functions -Wl,-z,relro -L/usr/lib/X11"/>
<configure name="LIBS" value="-lMagickCore -llcms2 -ltiff -lfreetype -ljpeg -llqr-1 -lglib-2.0 -lfftw3 -lfontconfig -lfreetype -lXext -lSM -lICE -lX11 -lXt -l$
<configure name="CXX" value="g++"/>
<configure name="CXXFLAGS" value="-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -pthread"/>
<configure name="DISTCHECK_CONFIG_FLAGS" value="'CFLAGS=-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security' 'CPPFLAGS=-D_FORT$
<configure name="TARGET_CPU" value="x86_64"/>
<configure name="TARGET_VENDOR" value="unknown"/>
<configure name="TARGET_OS" value="linux-gnu"/>
<configure name="HOST" value="x86_64-unknown-linux-gnu"/>
<configure name="FEATURES" value="OpenMP "/>
<configure name="DELEGATES" value="bzlib djvu fftw fontconfig freetype jbig jpeg jng jp2 lcms2 lqr lzma openexr pango png rsvg tiff x11 xml wmf zlib"/>
<configure name="COPYRIGHT" value="Copyright (C) 1999-2012 ImageMagick Studio LLC"/>
<configure name="WEBSITE" value="http://www.imagemagick.org"/>
<configure name="QuantumDepth" value="16"/>
</configuremap>
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Does PHP imagemagick support with Unicode?

Post by snibgo »

"pango:" needs the font to be installed, so it is listed on "convert -list font". If can't be used by simply giving the filename of the TTF file.
snibgo's IM pages: im.snibgo.com
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

There are a lot of English fonts but not mine so I have to past my Khmer fonts at there and add some option in configure like

FreeType --with-freetype=yes yes
FontConfig --with-fontconfig=yes yes

I hope this one can be work for me now try to edit and testing
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

OK now it is working very well.

Thank very much for helping me
hengsopheak
Posts: 16
Joined: 2017-03-21T07:45:32-07:00
Authentication code: 1151

Re: Does PHP imagemagick support with Unicode?

Post by hengsopheak »

unable to open image `"Hello World.png!"': No such file or directory @ error/blob.c/OpenBlob/2705
Post Reply