I18N_Arabic

# Source for file Hiero.php

Documentation is available at Hiero.php

1. <?php
2. /**
3. * ----------------------------------------------------------------------
4. *
5. * Copyright (c) 2006-2016 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-2016 Khaled Al-Sham'aa
76. *
77. * @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
78. * @link http://www.ar-php.org
79. */
81. /**
82. * Translate English word into Hieroglyphics
83. *
84. * @category I18N
85. * @package I18N_Arabic
86. * @author Khaled Al-Sham'aa <khaled@ar-php.org>
87. * @copyright 2006-2016 Khaled Al-Sham'aa
88. *
89. * @license LGPL <http://www.gnu.org/licenses/lgpl.txt>
90. * @link http://www.ar-php.org
91. */
92. class I18N_Arabic_Hiero
93. {
94. private $_language = 'Hiero';
96. /**
97. * Loads initialize values
98. *
99. * @ignore
100. */
101. public function __construct ()
102. {
103. }
105. /**
106. * Set the output language
107. *
108. * @param string $value Output language (Hiero or Phoenician)
109. *
110. * @return object $this to build a fluent interface
111. * @author Khaled Al-Sham'aa <khaled@ar-php.org>
112. */
113. public function setLanguage($value)
114. {
115. $value = strtolower($value);
117. if ($value == 'hiero' || $value == 'phoenician') {
118. $this->_language = $value;
119. }
121. return $this;
122. }
124. /**
125. * Get the output language
126. *
127. * @return string return current setting of the output language
128. * @author Khaled Al-Sham'aa <khaled@ar-php.org>
129. */
130. public function getLanguage()
131. {
132. return ucwords($this->_language);
133. }
135. /**
136. * Translate Arabic or English word into Hieroglyphics
137. *
138. * @param string $word Arabic or English word
139. * @param string $dir Writing direction [ltr, rtl, ttd, dtt] (default ltr)
140. * @param string $lang Input language [en, ar] (default en)
141. * @param integer $red Value of background red component (default is null)
142. * @param integer $green Value of background green component (default is null)
143. * @param integer $blue Value of background blue component (default is null)
144. *
145. * @return resource Image resource identifier
146. * @author Khaled Al-Sham'aa <khaled@ar-php.org>
147. */
148. public function str2graph(
149. $word, $dir = 'ltr', $lang = 'en', $red = null, $green = null, $blue = null
150. ) {
151. if ($this->_language == 'phoenician') {
152. define(MAXH, 40);
153. define(MAXW, 50);
154. } else {
155. define(MAXH, 100);
156. define(MAXW, 75);
157. }
159. // Note: there is no theh, khah, thal, dad, zah, and ghain in Phoenician
160. $arabic = array(
161. 'ا' => 'alef',
162. 'ب' => 'beh',
163. 'ت' => 'teh',
164. 'ث' => 'theh',
165. 'ج' => 'jeem',
166. 'ح' => 'hah',
167. 'خ' => 'khah',
168. 'د' => 'dal',
169. 'ذ' => 'thal',
170. 'ر' => 'reh',
171. 'ز' => 'zain',
172. 'س' => 'seen',
173. 'ش' => 'sheen',
174. 'ص' => 'sad',
175. 'ض' => 'dad',
176. 'ط' => 'tah',
177. 'ظ' => 'zah',
178. 'ع' => 'ain',
179. 'غ' => 'ghain',
180. 'ف' => 'feh',
181. 'ق' => 'qaf',
182. 'ك' => 'kaf',
183. 'ل' => 'lam',
184. 'م' => 'meem',
185. 'ن' => 'noon',
186. 'ه' => 'heh',
187. 'و' => 'waw',
188. 'ي' => 'yeh'
189. );
191. if ($lang != 'ar' && $this->_language == 'phoenician') {
192. include dirname(__FILE__).'/Transliteration.php';
194. $temp = new Transliteration();
195. $word = $temp->en2ar($word);
197. $temp = null;
198. $lang = 'ar';
199. }
201. if ($lang != 'ar') {
202. $word = strtolower($word);
203. } else {
204. $word = str_replace('ة', 'ت', $word);
205. $alef = array('ى', 'ؤ', 'ئ', 'ء', 'آ', 'إ', 'أ');
206. $word = str_replace($alef, '?', $word);
207. }
209. $chars = array();
210. $max = mb_strlen($word, 'UTF-8');
212. for ($i = 0; $i < $max; $i++) {
213. $chars[] = mb_substr($word, $i, 1, 'UTF-8');
214. }
216. if ($dir == 'rtl' || $dir == 'btt') {
217. $chars = array_reverse($chars);
218. }
220. $max_w = 0;
221. $max_h = 0;
223. foreach ($chars as $char) {
224. if ($lang == 'ar') {
225. $char = $arabic[$char];
226. }
228. if (file_exists(dirname(__FILE__)."/images/{$this->_language}/$char.gif")
229. ) {
230. list($width, $height) = getimagesize(
231. dirname(__FILE__)."/images/{$this->_language}/$char.gif"
232. );
233. } else {
234. $width = MAXW;
235. $height = MAXH;
236. }
238. if ($dir == 'ltr' || $dir == 'rtl') {
239. $max_w += $width;
240. if ($height > $max_h) {
241. $max_h = $height;
242. }
243. } else {
244. $max_h += $height;
245. if ($width > $max_w) {
246. $max_w = $width;
247. }
248. }
249. }
251. $im = imagecreatetruecolor($max_w, $max_h);
253. if ($red == null) {
254. $bck = imagecolorallocate($im, 0, 0, 255);
255. imagefill($im, 0, 0, $bck);
257. // Make the background transparent
258. imagecolortransparent($im, $bck);
259. } else {
260. $bck = imagecolorallocate($im, $red, $green, $blue);
261. imagefill($im, 0, 0, $bck);
262. }
264. $current_x = 0;
266. foreach ($chars as $char) {
267. if ($lang == 'ar') {
268. $char = $arabic[$char];
269. }
270. $filename = dirname(__FILE__)."/images/{$this->_language}/$char.gif";
272. if ($dir == 'ltr' || $dir == 'rtl') {
273. if (file_exists($filename)) {
274. list($width, $height) = getimagesize($filename);
276. $image = imagecreatefromgif($filename);
277. imagecopy(
278. $im, $image, $current_x, $max_h - $height,
279. 0, 0, $width, $height
280. );
281. } else {
282. $width = MAXW;
283. }
285. $current_x += $width;
286. } else {
287. if (file_exists($filename)) {
288. list($width, $height) = getimagesize($filename);
290. $image = imagecreatefromgif($filename);
291. imagecopy($im, $image, 0, $current_y, 0, 0, $width, $height);
292. } else {
293. $height = MAXH;
294. }
296. $current_y += $height;
297. }
298. }
300. return $im;
301. }

Documentation generated on Fri, 01 Jan 2016 10:26:04 +0200 by phpDocumentor 1.4.0