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