Nan
Nan

Reputation: 25

language readability for add text to image in php

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.

Upvotes: 0

Views: 99

Answers (1)

Hoog3059
Hoog3059

Reputation: 11

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

Upvotes: 1

Related Questions