0

I add text to image in php using the following code:

    $font_path = 'assets/bend/fonts/Arial.ttf';
    $text = 'Молдавия';
    imagettftext($stars, 40, 0, 150, 200, $white, $font_path, $text); 
    imagejpeg($stars, 'images/newtes1.jpg');

However, it fails to read non latin letters such as russian for example. It shows symbols like squares. I have changed different fonts which work otherwise, but when i want to add to the image it doesnt. I work with netbeans if it matters. Thanks in advance.

Nan
  • 25
  • 1
  • 8
  • check this post i think it covers you http://stackoverflow.com/questions/9458317/working-with-gd-imagettftext-and-utf-8-characters –  May 06 '16 at 07:38
  • My understanding is that netbeans is more forgiving for errors. So a smal mistake is corrected in netbeans php server, but on web you get an error. I can't see what the problem is but this is my understanding of netbeans – Andreas May 06 '16 at 07:39
  • Boys thanks a lot. it worked! – Nan May 13 '16 at 10:00

1 Answers1

1

Try this font: Arimo-Arial-Font

The code below works for me:

<?php
  $jpg_image = imagecreatefromjpeg('test.jpg');
  $text = 'Молдавия'; //Or any other text
  $font_path = "Arimo-Regular.ttf"; //Or any other font
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  imagettftext($jpg_image, 40, 0, 150, 200, $white, $font_path, $text); 
  imagejpeg($jpg_image, 'test.jpg');
?>

EDIT: you should use other fonts for languages like georgian, armenian and japanese, etc. The Arimo-Arial-Font only contains Latin and Russian characters.

Japanese Fonts

Georgian Fonts

Armenian Fonts

ps. Sorry if my english is bad

Hoog3059
  • 11
  • 1
  • 3
  • Hello Hoog3059, I youd like to say big thanks to you it worked perfectly. Just using the right font:) – Nan May 13 '16 at 09:59