├── README.md
├── texttotsticker.png
├── index.php
└── farsiGD.php
/README.md:
--------------------------------------------------------------------------------
1 | # text-to-sticker-bot
2 | THIS PROJECT IS HERE ONLY FOR EDUCATIONAL PURPOSE!
3 |
--------------------------------------------------------------------------------
/texttotsticker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mhrlife/text-to-sticker-bot/HEAD/texttotsticker.png
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | message)){
25 | $text = $update->message->text;
26 | if($text == "/start" || $text == '/help'){
27 | makeHTTPRequest('sendMessage',[
28 | 'chat_id'=>$update->message->chat->id,
29 | 'text'=>'Welcome to TEXT TO STICKER bot
30 |
31 | ▪️This robot convert your messages into a sticker
32 |
33 | ▪️be careful with your message to avoid overflow.
34 |
35 | ▪️now send me a message and i will convert it :)
36 |
37 | ▪️also you can Contact Me !',
38 | 'parse_mode'=>'HTML',
39 | 'disable_web_page_preview'=>true
40 | ]);
41 | return false;
42 | }
43 |
44 | /**
45 | * Making the Sticker
46 | */
47 |
48 |
49 | $exploded_text = explode("\n",$text);
50 | foreach($exploded_text as $similer_text){
51 | if(mb_strlen($similer_text) > 50 ){
52 | echo 'MAX 20 CHARACTERS';
53 | return false;
54 | }
55 | }
56 | //
57 | //$count_lines = count($exploded_text);
58 | //$resource_image = imagecreatetruecolor(512,512);
59 | //$bgImage = imagecolorallocate($resource_image,236, 240, 241);
60 | //imagefilledrectangle($resource_image,0,0,512,512,$bgImage);
61 | //imagettftext($resource_image,14,0,10,10,imagecolorallocate($resource_image,0,0,0),__DIR__.'/font.ttf',
62 | // fagd($text,'fa','nastaligh')
63 | // );
64 | //
65 | //imagepng($resource_image,'log.png');
66 | //
67 |
68 | $image = new Imagick('texttotsticker.png');
69 |
70 |
71 | $draw = new ImagickDraw();
72 | $draw->setFillColor('white');
73 | $draw->setFont('font.ttf');
74 | $draw->setFontSize(35);
75 | $draw->setTextEncoding('utf-8');
76 | $draw->setTextInterLineSpacing(30);
77 | $draw->setGravity(Imagick::GRAVITY_CENTER);
78 | preg_match('/([a-zA-Z]*)/',$text,$matches,PREG_OFFSET_CAPTURE);
79 | var_dump($matches);
80 | if(!isset($matches[0][0]) || $matches[0][0] == ""){
81 | $image->annotateImage($draw,0,0,0,str_replace("{DIF}","\n",$gd->persianText((implode("{DIF}",array_reverse($exploded_text))),'fa','normal')));
82 | }else{
83 | $image->annotateImage($draw,0,0,0,$text);
84 | }
85 | //$image->annotateImage($draw,0,0,0,str_replace("*********#**********","\n",$gd->persianText((implode("*********#**********",array_reverse($exploded_text))),'fa','normal')));
86 | $image->setImageFormat('png');
87 | $theSticker = $image;
88 |
89 | $tmpFile = tmpfile();
90 | fwrite($tmpFile,$theSticker);
91 | fseek($tmpFile,0);
92 |
93 | $meta = stream_get_meta_data($tmpFile);
94 | $filePath = $meta['uri'];
95 |
96 |
97 | /**
98 | * end Making the Sticker
99 | */
100 |
101 | echo 'the PATH :';
102 | echo $filePath;
103 | echo "\n";
104 |
105 | var_dump(makeHTTPRequest('sendSticker',[
106 | 'chat_id'=>$update->message->chat->id,
107 | 'sticker'=> new CURLFile($filePath)
108 | ]));
109 |
110 |
111 |
112 | }
113 |
114 |
115 |
116 | file_put_contents('the_log',ob_get_clean());
117 |
--------------------------------------------------------------------------------
/farsiGD.php:
--------------------------------------------------------------------------------
1 | array('ﺂ', 'ﺂ', 'آ'),
8 | 'ا' => array('ﺎ', 'ﺎ', 'ا'),
9 | 'ب' => array('ﺐ', 'ﺒ', 'ﺑ'),
10 | 'پ' => array('ﭗ', 'ﭙ', 'ﭘ'),
11 | 'ت' => array('ﺖ', 'ﺘ', 'ﺗ'),
12 | 'ث' => array('ﺚ', 'ﺜ', 'ﺛ'),
13 | 'ج' => array('ﺞ', 'ﺠ', 'ﺟ'),
14 | 'چ' => array('ﭻ', 'ﭽ', 'ﭼ'),
15 | 'ح' => array('ﺢ', 'ﺤ', 'ﺣ'),
16 | 'خ' => array('ﺦ', 'ﺨ', 'ﺧ'),
17 | 'د' => array('ﺪ', 'ﺪ', 'ﺩ'),
18 | 'ذ' => array('ﺬ', 'ﺬ', 'ﺫ'),
19 | 'ر' => array('ﺮ', 'ﺮ', 'ﺭ'),
20 | 'ز' => array('ﺰ', 'ﺰ', 'ﺯ'),
21 | 'ژ' => array('ﮋ', 'ﮋ', 'ﮊ'),
22 | 'س' => array('ﺲ', 'ﺴ', 'ﺳ'),
23 | 'ش' => array('ﺶ', 'ﺸ', 'ﺷ'),
24 | 'ص' => array('ﺺ', 'ﺼ', 'ﺻ'),
25 | 'ض' => array('ﺾ', 'ﻀ', 'ﺿ'),
26 | 'ط' => array('ﻂ', 'ﻄ', 'ﻃ'),
27 | 'ظ' => array('ﻆ', 'ﻈ', 'ﻇ'),
28 | 'ع' => array('ﻊ', 'ﻌ', 'ﻋ'),
29 | 'غ' => array('ﻎ', 'ﻐ', 'ﻏ'),
30 | 'ف' => array('ﻒ', 'ﻔ', 'ﻓ'),
31 | 'ق' => array('ﻖ', 'ﻘ', 'ﻗ'),
32 | 'ک' => array('ﻚ', 'ﻜ', 'ﻛ'),
33 | 'گ' => array('ﮓ', 'ﮕ', 'ﮔ'),
34 | 'ل' => array('ﻞ', 'ﻠ', 'ﻟ'),
35 | 'م' => array('ﻢ', 'ﻤ', 'ﻣ'),
36 | 'ن' => array('ﻦ', 'ﻨ', 'ﻧ'),
37 | 'و' => array('ﻮ', 'ﻮ', 'ﻭ'),
38 | 'ی' => array('ﯽ', 'ﯿ', 'ﯾ'),
39 | 'ك' => array('ﻚ', 'ﻜ', 'ﻛ'),
40 | 'ي' => array('ﻲ', 'ﻴ', 'ﻳ'),
41 | 'أ' => array('ﺄ', 'ﺄ', 'ﺃ'),
42 | 'ؤ' => array('ﺆ', 'ﺆ', 'ﺅ'),
43 | 'إ' => array('ﺈ', 'ﺈ', 'ﺇ'),
44 | 'ئ' => array('ﺊ', 'ﺌ', 'ﺋ'),
45 | 'ة' => array('ﺔ', 'ﺘ', 'ﺗ')
46 | );
47 | public $tahoma = array(
48 | 'ه' => array('ﮫ', 'ﮭ', 'ﮬ')
49 | );
50 | public $normal = array(
51 | 'ه' => array('ﻪ', 'ﻬ', 'ﻫ')
52 | );
53 | public $mp_chars = array('آ', 'ا', 'د', 'ذ', 'ر', 'ز', 'ژ', 'و', 'أ', 'إ', 'ؤ');
54 | public $ignorelist = array('', 'ٌ', 'ٍ', 'ً', 'ُ', 'ِ', 'َ', 'ّ', 'ٓ', 'ٰ', 'ٔ', 'ﹶ', 'ﹺ', 'ﹸ', 'ﹼ', 'ﹾ', 'ﹴ', 'ﹰ', 'ﱞ', 'ﱟ', 'ﱠ', 'ﱡ', 'ﱢ', 'ﱣ',);
55 | public $openClose = array('>', ')', '}', ']', '<', '(', '{', '[');
56 | public $en_chars = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
57 | ///
58 | public function persianText($str, $z="", $method='tahoma', $farsiNumber=true) {
59 | $en_str = '';
60 | $runWay = '';
61 | if ($method == 'tahoma') {
62 | $this->p_chars = array_merge($this->p_chars, $this->tahoma);
63 | } else {
64 | $this->p_chars = array_merge($this->p_chars, $this->normal);
65 | }
66 | $str_len = $this->utf8_strlen($str);
67 | preg_match_all("/./u", $str, $ar);
68 | for ($i = 0; $i < $str_len; $i++) {
69 | $gatherNumbers = false;
70 | $runWay = null;
71 | $str1 = $ar[0][$i];
72 | if (in_array($ar[0][$i + 1], $this->ignorelist)) {
73 | $str_next = $ar[0][$i + 2];
74 | if ($i == 2)
75 | $str_back = $ar[0][$i - 2];
76 | if ($i != 2)
77 | $str_back = $ar[0][$i - 1];
78 | }elseif (!in_array($ar[0][$i - 1], $this->ignorelist)) {
79 | $str_next = $ar[0][$i + 1];
80 | if ($i != 0)
81 | $str_back = $ar[0][$i - 1];
82 | }else {
83 | if (isset($ar[0][$i + 1]) && !empty($ar[0][$i + 1])) {
84 | $str_next = $ar[0][$i + 1];
85 | } else {
86 | $str_next = $ar[0][$i - 1];
87 | }
88 | if ($i != 0)
89 | $str_back = $ar[0][$i - 2];
90 | }
91 | if (!in_array($str1, $this->ignorelist)) {
92 | if (array_key_exists($str1, $this->p_chars)) {
93 | if (!$str_back or $str_back == " " or !array_key_exists($str_back, $this->p_chars)) {
94 | if (!array_key_exists($str_back, $this->p_chars) and !array_key_exists($str_next, $this->p_chars))
95 | $output = $str1 . $output;
96 | else
97 | $output = $this->p_chars[$str1][2] . $output;
98 | continue;
99 | }elseif (array_key_exists($str_next, $this->p_chars) and array_key_exists($str_back, $this->p_chars)) {
100 | if (in_array($str_back, $this->mp_chars) and array_key_exists($str_next, $this->p_chars)) {
101 | $output = $this->p_chars[$str1][2] . $output;
102 | } else {
103 | $output = $this->p_chars[$str1][1] . $output;
104 | }
105 | continue;
106 | } elseif (array_key_exists($str_back, $this->p_chars) and !array_key_exists($str_next, $this->p_chars)) {
107 | if (in_array($str_back, $this->mp_chars)) {
108 | // just font FREEFARSI work for H at end of sth that not connected like Dah!
109 | $output = $str1 . $output;
110 | } else {
111 | $output = $this->p_chars[$str1][0] . $output;
112 | }
113 | continue;
114 | }
115 | } elseif ($z == "fa") {
116 | $number = array("٠", "١", "٢", "٣", "٤", "٥", "٦", "٧", "٨", "٩", "۴", "۵", "۶", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
117 | switch ($str1) {
118 | case ")" : $str1 = "(";
119 | break;
120 | case "(" : $str1 = ")";
121 | break;
122 | case "}" : $str1 = "{";
123 | break;
124 | case "{" : $str1 = "}";
125 | break;
126 | case "]" : $str1 = "[";
127 | break;
128 | case "[" : $str1 = "]";
129 | break;
130 | case ">" : $str1 = "<";
131 | break;
132 | case "<" : $str1 = ">";
133 | break;
134 | }
135 | if (in_array($str1, $number)) {
136 | if ( $farsiNumber ) {
137 | $num .= $this->fa_number($str1);
138 | $runWay[] = '1';
139 | } else {
140 | $num .= $str1;
141 | $runWay[] = '2';
142 | }
143 | $str1 = "";
144 | }
145 |
146 | if ( !in_array($str_next, $number) ) {
147 | if ( in_array(strtolower($str1), $this->en_chars) or (($str1==' ' or $str1=='.') and $en_str!='' and !in_array($str_next, $this->p_chars)) ) {
148 | $en_str .= $str1 . $num;
149 | $str1 = '';
150 | $runWay[] = '3';
151 | } else {
152 | if ( $en_str!='' ) {
153 | if ( $i+1==$str_len ) {
154 | $runWay[] = '3.5';
155 | $str1 = $str1.$num;
156 | } else {
157 | $en_str .= $str1 .$num;
158 | $runWay[] = '4';
159 | }
160 | } else {
161 | $str1 = $str1.$num;
162 | $runWay[] = '5';
163 | }
164 |
165 | }
166 | $num = '';
167 | }
168 | if ( $en_str!='' or ($str1!='' and $i==0 and ( !array_key_exists($str_next, $this->p_chars) and $str_next!=' ' )) or $gatherNumbers ) { //or ($str1!='' and $i==0)
169 | if ( !array_key_exists($str1, $this->p_chars) ) {
170 | if ( !array_key_exists($str_next, $this->p_chars) and $str_next!=' ' and !in_array($str_next, $this->openClose) ) {
171 | $en_str = $en_str.$str1;
172 | $runWay[] = '6';
173 | } else {
174 | if ( in_array($ar[0][$i+2], $this->en_chars) ) {
175 | $en_str = $en_str.$str1;
176 | $runWay[] = '7';
177 | } else {
178 |
179 | if ( $str_next==' ' and ( in_array($ar[0][$i+2], $number) or in_array(strtolower($ar[0][$i+2]), $this->en_chars) ) ) {
180 | $en_str = $en_str.$str1;
181 | $runWay[] = '8';
182 | } else {
183 | //if ( in_array($str_next, $this->openClose) and in_array(strtolower($str_back), $this->en_chars) ) {
184 | // $output = $output . $en_str;
185 | // $en_str = '';
186 | // $en_str = $en_str.$str1;
187 | // $i++;
188 | // continue;
189 | //$output = $output . $en_str;
190 | //$en_str='';
191 | // $runWay[] = '9.5';
192 | // } else {
193 | $output = $en_str . $output;
194 | $en_str = '';
195 | $runWay[] = '9';
196 | // }
197 | }
198 |
199 | }
200 | }
201 |
202 | } else {
203 | if ( $num ) {
204 | $en_str = $en_str .$num;
205 | $runWay[] = '10';
206 | } else {
207 | $output = $en_str . $str1 . $output ;
208 | $en_str = '';
209 | $runWay[] = '11';
210 | }
211 | }
212 |
213 | } else {
214 |
215 | if ( in_array($str1, $number) and $str_next=='.' and in_array($ar[0][$i+2], $number) ) {
216 | $en_str = $str1;
217 | $runWay[] = '12';
218 | } else {
219 | //if ( in_array($str1, $this->openClose) and in_array($str_next, $this->en_chars) ) {
220 | // $output = $str1.$output ;
221 | // $runWay[] = '13';
222 | //} else {
223 | $output = $str1. $output ;
224 | $runWay[] = '14';
225 | // }
226 | }
227 | }
228 | } else {
229 | if (($str1 == "،") or ($str1 == "؟") or ($str1 == "ء") or (array_key_exists($str_next, $this->p_chars) and array_key_exists($str_back, $this->p_chars)) or
230 | ($str1 == " " and array_key_exists($str_back, $this->p_chars)) or ($str1 == " " and array_key_exists($str_next, $this->p_chars))) {
231 | if ($e_output) {
232 | $output = $e_output . $output;
233 | $e_output = "";
234 | }
235 | $output = $str1 . $output;
236 | } else {
237 | $e_output.=$str1;
238 | if (array_key_exists($str_next, $this->p_chars) or $str_next == "") {
239 | $output = $e_output . $output;
240 | $e_output = "";
241 | }
242 | }
243 | }
244 | } else {
245 | $output = $str1 . $output;
246 | }
247 |
248 | //fb("str1: {$str1} | num: {$num} | output: {$output} | enSter: {$en_str} | strNex: {$str_next} | strBack: {$str_back}| path: ". implode('-',$runWay) );
249 |
250 | $str_next = null;
251 | $str_back = null;
252 | }
253 | if ( $en_str!='' ) {
254 | $output = $en_str . $output ;
255 | }
256 | return $output;
257 | }
258 | public function fa_number($num) {
259 | $AF = array(
260 | 0 => "٠",
261 | 1 => "١",
262 | 2 => "٢",
263 | 3 => "٣",
264 | 4 => "۴",
265 | 5 => "۵",
266 | 6 => "۶",
267 | 7 => "٧",
268 | 8 => "٨",
269 | 9 => "٩"
270 | );
271 | $af_date = NULL;
272 | $chars = preg_split('//', $num, -1, PREG_SPLIT_NO_EMPTY);
273 | foreach ($chars as $key => $val) {
274 | $af_num = NULL;
275 | switch ($val) {
276 | case "0";
277 | $af_num = $AF[0];
278 | break;
279 | case "1":
280 | $af_num = $AF[1];
281 | break;
282 | case "2":
283 | $af_num = $AF[2];
284 | break;
285 | case "3":
286 | $af_num = $AF[3];
287 | break;
288 | case "4":
289 | $af_num = $AF[4];
290 | break;
291 | case "5":
292 | $af_num = $AF[5];
293 | break;
294 | case "6":
295 | $af_num = $AF[6];
296 | break;
297 | case "7":
298 | $af_num = $AF[7];
299 | break;
300 | case "8":
301 | $af_num = $AF[8];
302 | break;
303 | case "9":
304 | $af_num = $AF[9];
305 | break;
306 | default :
307 | $af_num = $val;
308 | }
309 | $af_date .=$af_num;
310 | }
311 | return $af_date;
312 | }
313 | }
314 | ?>
--------------------------------------------------------------------------------