php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #72912 GD and rtl languages
Submitted: 2016-08-21 11:08 UTC Modified: 2016-09-14 14:05 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: hirad dot daneshvar at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: GD related
PHP Version: 5.6.25 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hirad dot daneshvar at gmail dot com
New email:
PHP Version: OS:

 

 [2016-08-21 11:08 UTC] hirad dot daneshvar at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.imagettftext
---

I can add text watermarks to my image, however the text must be a Left To Right language. How can I use RTL languages such as Persian to add a watermark?

For example a text like سلام will be added like م ا ل س.

I have searched A LOT, and all I found was custom functions to do so. However persian letters unlike Latin letters should be connected. For example in the word 'Hello' there is a space in between 'H' and 'e', in the same word in persian, which is 'سلام', the first letter 'س' is connected to 'ل'. To do this we have to replace the letters with the correct connected symbol to do the trick. Using this approach when applying different fonts to our word, the letters that we replaced with their connected symbol are written in an ugly font. I was wondering if there was an extension or library to install and handle this using GD. 


Test script:
---------------
<?php
// Set the content-type
header('Content-Type: image/png');

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'سلام';
$font = 'yekan.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

imagepng($im);
imagedestroy($im);
?>

Expected result:
----------------
When I run the code I expect to see سلام in an image

Actual result:
--------------
When I run the code I get م ا ل س in an image

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-21 12:15 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2016-08-21 12:15 UTC] cmb@php.net
Indeed, neither RTL languages nor GPOS kerning is currently
supported in GD. PRs against <https://github.com/libgd/libgd> are
welcome!
 [2016-08-22 15:21 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 [2016-08-22 15:21 UTC] cmb@php.net
> Indeed, neither RTL languages nor GPOS kerning is currently
> supported in GD.

I've been not up-to-date. Actually, there is CTL support in master
since <https://github.com/libgd/libgd/pull/196> has been merged.
 [2016-09-14 14:05 UTC] cmb@php.net
-Status: Verified +Status: Duplicate
 [2016-09-14 14:05 UTC] cmb@php.net
I've just found bug #43899 which is about the same issue, so I'm
closing this ticket as duplicate.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 22 00:01:30 2024 UTC