Arabic Glyphs to Render Arabic Text:

Takes Arabic text as an input and performs Arabic glyph joining on it and outputs a UTF-8 hexadecimals stream that is no longer logically arranged but in a visual order which gives readable results when formatted with a simple Unicode rendering just like GD and PDF libraries that does not handle basic connecting glyphs of Arabic language yet but simply outputs all stand alone glyphs in left-to-right order.

What is happening?
Computers are designed to handle the subset of the Latin script required to manipulate American English first and foremost. Every other writing system is an afterthought, and Arabic is particularly poorly served. Most of the images in Nope, Not Arabic archive are the result of non-Arab graphic designers pasting Arabic text into mainstream graphic design software that cannot handle anything but Latin characters and not checking with a native speaker.


Example Output 1:


Example Code 1:

<?php
    
// Create the image
    
$im = @imagecreatefromgif('images/bg.gif');

    
// Create some colors
    
$black imagecolorallocate($im000);
    
$blue  imagecolorallocate($im00255);
    
$white imagecolorallocate($im255255255);

    
// Replace by your own font full path and name
    
$path substr(
        
$_SERVER['SCRIPT_FILENAME'], 0
        
strrpos($_SERVER['SCRIPT_FILENAME'], '/')
    );
    
$font $path.'/fonts/Amiri-Regular.ttf';

    
// UTF-8 charset
    
$text 'بسم الله الرحمن الرحيم';
    
imagefill($im00$white);
    
imagettftext($im2001050$blue$font'UTF-8:');
    
imagettftext($im20025050$black$font$text);

    
/*
      // Autoload files using Composer autoload
      require_once __DIR__ . '/../vendor/autoload.php';
    */

    
require '../src/Arabic.php';
    
$Arabic = new \ArPHP\I18N\Arabic();

    
$text 'بسم الله الرحمن الرحيم';
    $    
ext $Arabic->utf8Glyphs($text);

    
imagettftext($im20010100$blue$font'Arabic Glyphs:');
    
imagettftext($im200250100$black$font$text);

    
// Using imagepng() results in clearer text compared with imagejpeg()
    
imagepng($im);
    
imagedestroy($im);

Related Documentation: utf8Glyphs