I18N_Arabic
[ class tree: I18N_Arabic ] [ index: I18N_Arabic ] [ all elements ]

Source for file Hiero.php

Documentation is available at Hiero.php

  1. <?php
  2. /**
  3.  * ----------------------------------------------------------------------
  4.  *  
  5.  * Copyright (c) 2006-2013 Khaled Al-Sham'aa.
  6.  *  
  7.  * http://www.ar-php.org
  8.  *  
  9.  * PHP Version 5
  10.  *  
  11.  * ----------------------------------------------------------------------
  12.  *  
  13.  * LICENSE
  14.  *
  15.  * This program is open source product; you can redistribute it and/or
  16.  * modify it under the terms of the GNU Lesser General Public License (LGPL)
  17.  * as published by the Free Software Foundation; either version 3
  18.  * of the License, or (at your option) any later version.
  19.  *  
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  * GNU Lesser General Public License for more details.
  24.  *  
  25.  * You should have received a copy of the GNU Lesser General Public License
  26.  * along with this program.  If not, see <http://www.gnu.org/licenses/lgpl.txt>.
  27.  *  
  28.  * ----------------------------------------------------------------------
  29.  *  
  30.  * Class Name: Translate English word into Hieroglyphics
  31.  *  
  32.  * Filename:   Hiero.php
  33.  *  
  34.  * Original    Author(s): Khaled Al-Sham'aa <khaled@ar-php.org>
  35.  *  
  36.  * Purpose:    Translate English word into Hieroglyphics
  37.  *              
  38.  * ----------------------------------------------------------------------
  39.  *  
  40.  * Translate English word into Hieroglyphics
  41.  *
  42.  * Royality is made affordable, and within your reach. Now you can have The
  43.  * Royal Cartouche custome made in Egypt in 18 Kt. Gold with your name
  44.  * translated and inscribed in Hieroglyphic.
  45.  * 
  46.  * Originally, the Cartouche was worn only by the Pharaohs or Kings of Egypt.
  47.  * The Pharaoh was considered a living God and his Cartouche was his insignia.
  48.  * The "Magical Oval" in which the Pharaoh's first name was written was intended
  49.  * to protect him from evil spirits both while he lived and in the afterworld
  50.  * when entombed.
  51.  * 
  52.  * Over the past 5000 years the Cartouche has become a universal symbol of long
  53.  * life, good luck and protection from any evil.
  54.  * 
  55.  * Now you can acquire this ancient pendent handmade in Egypt from pure 18 Karat
  56.  * Egyptian gold with your name spelled out in the same way as King Tut, Ramses,
  57.  * Queen Nefertiti did.
  58.  *
  59.  * Example:
  60.  * <code>
  61.  *     include('./I18N/Arabic.php');
  62.  *     $obj = new I18N_Arabic('Hiero');
  63.  * 
  64.  *     $word = $_GET['w'];
  65.  *     $im   = $obj->str2hiero($word);
  66.  *      
  67.  *     header ("Content-type: image/jpeg");
  68.  *     imagejpeg($im, '', 80);
  69.  *     ImageDestroy($im);
  70.  * </code>
  71.  *             
  72.  * @category  I18N
  73.  * @package   I18N_Arabic
  74.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  75.  * @copyright 2006-2013 Khaled Al-Sham'aa
  76.  *    
  77.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  78.  * @link      http://www.ar-php.org
  79.  */
  80.  
  81. // New in PHP V5.3: Namespaces
  82. // namespace I18N\Arabic;
  83. // 
  84. // $obj = new I18N\Arabic\Hiero();
  85. // 
  86. // use I18N\Arabic;
  87. // $obj = new Arabic\Hiero();
  88. //
  89. // use I18N\Arabic\Hiero as Hiero;
  90. // $obj = new Hiero();
  91.  
  92. /**
  93.  * Translate English word into Hieroglyphics
  94.  *  
  95.  * @category  I18N
  96.  * @package   I18N_Arabic
  97.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  98.  * @copyright 2006-2013 Khaled Al-Sham'aa
  99.  *    
  100.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  101.  * @link      http://www.ar-php.org
  102.  */ 
  103. {
  104.     private $_language 'Hiero';
  105.  
  106.     /**
  107.      * Loads initialize values
  108.      *
  109.      * @ignore
  110.      */         
  111.     public function __construct ()
  112.     {
  113.     }
  114.  
  115.     /**
  116.      * Set the output language
  117.      *      
  118.      * @param string $value Output language (Hiero or Phoenician)
  119.      *      
  120.      * @return object $this to build a fluent interface
  121.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  122.      */
  123.     public function setLanguage($value)
  124.     {
  125.         $value strtolower($value);
  126.         
  127.         if ($value == 'hiero' || $value == 'phoenician'{
  128.             $this->_language $value;
  129.         }
  130.         
  131.         return $this;
  132.     }
  133.  
  134.     /**
  135.      * Get the output language
  136.      *      
  137.      * @return string return current setting of the output language
  138.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  139.      */
  140.     public function getLanguage()
  141.     {
  142.         return ucwords($this->_language);
  143.     }
  144.             
  145.     /**
  146.     * Translate Arabic or English word into Hieroglyphics
  147.     *      
  148.     * @param string  $word  Arabic or English word
  149.     * @param string  $dir   Writing direction [ltr, rtl, ttd, dtt] (default ltr)
  150.     * @param string  $lang  Input language [en, ar] (default en)
  151.     * @param integer $red   Value of background red component (default is null)
  152.     * @param integer $green Value of background green component (default is null)
  153.     * @param integer $blue  Value of background blue component (default is null)
  154.     *      
  155.     * @return resource Image resource identifier
  156.     * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  157.     */
  158.     public function str2graph(
  159.         $word$dir 'ltr'$lang 'en'$red null$green null$blue null
  160.     {
  161.         if ($this->_language == 'phoenician'{
  162.             define(MAXH40);
  163.             define(MAXW50);
  164.         else {
  165.             define(MAXH100);
  166.             define(MAXW75);
  167.         }
  168.  
  169.         // Note: there is no theh, khah, thal, dad, zah, and ghain in Phoenician
  170.         $arabic array(
  171.             'ا' => 'alef',
  172.             'ب' => 'beh',
  173.             'ت' => 'teh',
  174.             'ث' => 'theh',
  175.             'ج' => 'jeem',
  176.             'ح' => 'hah',
  177.             'خ' => 'khah',
  178.             'د' => 'dal',
  179.             'ذ' => 'thal',
  180.             'ر' => 'reh',
  181.             'ز' => 'zain',
  182.             'س' => 'seen',
  183.             'ش' => 'sheen',
  184.             'ص' => 'sad',
  185.             'ض' => 'dad',
  186.             'ط' => 'tah',
  187.             'ظ' => 'zah',
  188.             'ع' => 'ain',
  189.             'غ' => 'ghain',
  190.             'ف' => 'feh',
  191.             'ق' => 'qaf',
  192.             'ك' => 'kaf',
  193.             'ل' => 'lam',
  194.             'م' => 'meem',
  195.             'ن' => 'noon',
  196.             'ه' => 'heh',
  197.             'و' => 'waw',
  198.             'ي' => 'yeh'
  199.         );
  200.                 
  201.         if ($lang != 'ar' && $this->_language == 'phoenician'{
  202.             include dirname(__FILE__).'/Transliteration.php';
  203.  
  204.             $temp new Transliteration();
  205.             $word $temp->en2ar($word);
  206.  
  207.             $temp null;
  208.             $lang 'ar';
  209.         }
  210.  
  211.         if ($lang != 'ar'{
  212.             $word strtolower($word);
  213.         else {
  214.             $word str_replace('ة''ت'$word);
  215.             $alef array('ى''ؤ''ئ''ء''آ''إ''أ');
  216.             $word str_replace($alef'?'$word);
  217.         }
  218.         
  219.         $chars array();
  220.         $max   mb_strlen($word'UTF-8');
  221.  
  222.         for ($i 0$i $max$i++{
  223.             $chars[mb_substr($word$i1'UTF-8');
  224.         }
  225.  
  226.         if ($dir == 'rtl' || $dir == 'btt'{
  227.             $chars array_reverse($chars);
  228.         }
  229.  
  230.         $max_w 0;
  231.         $max_h 0;
  232.         
  233.         foreach ($chars as $char{
  234.             if ($lang == 'ar'{
  235.                 $char $arabic[$char];
  236.             }
  237.  
  238.             if (file_exists(dirname(__FILE__)."/images/{$this->_language}/$char.gif")
  239.             ) {
  240.                 list($width, $height) = getimagesize(
  241.                     dirname(__FILE__)."/images/{$this->_language}/$char.gif"
  242.                 );
  243.             } else {
  244.                 $width  = MAXW;
  245.                 $height = MAXH;
  246.             }
  247.             
  248.             if ($dir == 'ltr' || $dir == 'rtl') {
  249.                 $max_w += $width;
  250.                 if ($height > $max_h) { 
  251.                     $max_h = $height; 
  252.                 }
  253.             } else {
  254.                 $max_h += $height;
  255.                 if ($width > $max_w) { 
  256.                     $max_w = $width; 
  257.                 }
  258.             }
  259.         }
  260.  
  261.         $im = imagecreatetruecolor($max_w, $max_h);
  262.         
  263.         if ($red == null) {
  264.             $bck = imagecolorallocate($im, 0, 0, 255);
  265.             imagefill($im, 0, 0, $bck);
  266.  
  267.             // Make the background transparent
  268.             imagecolortransparent($im, $bck);
  269.         } else {
  270.             $bck = imagecolorallocate($im, $red, $green, $blue);
  271.             imagefill($im, 0, 0, $bck);
  272.         }
  273.  
  274.         $current_x = 0;
  275.         
  276.         foreach ($chars as $char) {
  277.             if ($lang == 'ar') {
  278.                 $char = $arabic[$char];
  279.             }
  280.             $filename = dirname(__FILE__)."/images/{$this->_language}/$char.gif";
  281.             
  282.             if ($dir == 'ltr' || $dir == 'rtl') {
  283.                 if (file_exists($filename)) {
  284.                     list($width, $height) = getimagesize($filename);
  285.  
  286.                     $image = imagecreatefromgif($filename);
  287.                     imagecopy(
  288.                         $im, $image, $current_x, $max_h - $height, 
  289.                         0, 0, $width, $height
  290.                     );
  291.                 } else {
  292.                     $width = MAXW;
  293.                 }
  294.     
  295.                 $current_x += $width;
  296.             } else {
  297.                 if (file_exists($filename)) {
  298.                     list($width, $height) = getimagesize($filename);
  299.  
  300.                     $image = imagecreatefromgif($filename);
  301.                     imagecopy($im, $image, 0, $current_y, 0, 0, $width, $height);
  302.                 } else {
  303.                     $height = MAXH;
  304.                 }
  305.     
  306.                 $current_y += $height;
  307.             }
  308.         }
  309.         
  310.         return $im;
  311.     }

Documentation generated on Mon, 14 Jan 2013 17:48:50 +0100 by phpDocumentor 1.4.0