Jump to content

Printing Japanese in GD?


Nolongerused3921

Recommended Posts

Basically I've created a database with Japanese in it, under UTF-8 and have gotten it into PHP properly - I am able to print_r the table and it shows the Japanese properly, however I can not get GD to print it - even using a hiragana (Its Hiragana, not kata or kanji) ttf font and imagettftext...

 

Has anyone worked with GD + foreign languages before? Is there a native PHP font that I can use, rather than a font I found online? If not, or even if so - whats the best way to get Japanese into an image, using GD?

I plan on using Hiragana, Katakana, AND Kanji at some point (Just hiragana for now), so it'd be nice to have a native PHP UTF-8 Japanese font available, rather than hunting all over for new fonts and all that.

Link to comment
Share on other sites

Thats what I'm asking, does PHP/GD have (Access to) a UTF-8 font?

In short, yes. I'll try and give you an example.

 

If the font you have (hiragana) is in ttf format, then you must have it in the same font that the code is in.

 

<?php

$font = "HIRAGANA.ttf";

$image = ImageCreate(300,100);

$black = ImageColorAllocate($image, 0, 0, 0);
$white = ImageColorAllocate($image, 255,255,255);

ImageFill($image, 0, 0, $black);

Imagettftext($image, 12, 0, 20,30,$white,$font,"Your text here");

header("Content-Type: image/gif");
Imagegif($image);
Imagegif($image, "image.gif");
imagedestroy($image);

?>

 

That works.

 

That code, with different image dimensions produces this

 

image.gif

Link to comment
Share on other sites

Sadly that won't work, as the font isn't unicode (And thus won't work seeing as Japanese isn't a Romance language).

Basically the text you just typed doesn't make sense, it comes out to being:

u - chi

t - e

t#2 - dji (I believe)

e - u

x - ...Well, you get the idea

 

 

 

Hmm.. true, but what I typed in there was Your Text Here, which came up as complete nonsense in Japanese. The Hiragana font is for Japanese so each letter translates to the japanese meaning, thus you have to write it accordingly.

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.