1 <?php
2
#####################################
3 #     Divxmania ArtWorks v. 2       #
4 #####################################
5 #                                   #
6 #   rev.    2.0.5                   #
7 #   start   02/01/2003 16.20 +0100  #
8 #   last    12/11/2005 20.45 +0100  #
9 #                                   #
10 #####################################
11 #     Divxmania.it 2002-2005       #
12 #####################################
13
14
15 /*#########################################################################################
16 This script is free software; you can redistribute it and/or
17 modify it under the terms of the GNU Lesser General Public
18 License as published by the Free Software Foundation; either
19 version 2.1 of the License, or (at your option) any later version.
20
21 This library is distributed in the hope that it will be useful (or at least funny),
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24 Lesser General Public License for more details.
25
26 You should have received a copy of the GNU Lesser General Public
27 License along with this library; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
30 If you have any questions or comments, please email or visit the website:
31
32 CereS <ceres@divxmania.it>
33
34 http://pic2text.divxmania.it/
35
36 #########################################################################################*/
37
38 //Senza questo non funziona, e ve lo avevo gi detto...
39
if(DIO != "CANE") die();
40
41
//RTF
42
include(INCLUDE_DIR "class_rtf.php");
43
44
$rtf = new rtf();
45
46
//Mailer
47
include(INCLUDE_DIR."mailer".DIR_SEP."class.phpmailer.php");
48
$mail = new PHPMailer();
49
$mail->PluginDir INCLUDE_DIR."mailer".DIR_SEP;
50
$mail->SetLanguage(strtolower(substr($_SESSION[language],0,2)), INCLUDE_DIR."mailer".DIR_SEP."language".DIR_SEP);
51
52
//Zip
53
include(INCLUDE_DIR "ziplib.php");
54
55
$conv_mode $globali['action'];        //Valid: text | ascii | table
56
$char_to_use $globali['lettere'];        //Valid: Any ascii string
57
$random_mode $globali['random'];        //Boolean
58
$custom_chars $globali['custom_chars'];    //Boolean
59
60
$font_corr = array(
61
=> 1,
62
=> 1,
63
=> 1,
64
=> 2,
65
=> 1,
66
=> 1.5,
67
=> 1.6,
68
=> 1,
69
10 => 1.6,
70
13 => 1.6,
71
16 => 1.6,
72
20 => 1.6
73
);
74
//Conversion start here!
75
76
if ( $globali[action] == "download" && $globali[start_download] )
77 {
78     
$file TMP_DIR $globali[base_name] . "." .  $globali[type];
79     if (
filesize($file) > 300*1024 && $globali[type] != "jpg")
80     {
81         
$file file_get_contents($file); 
82
83         
$zipfile = new Ziplib;
84         
$zipfile->zl_add_file($file,"image.".$globali[type],"g9");    
85         
$zfile $zipfile->zl_pack("Downloaded from http://pic2text.divxmania.it");
86
87         
header("content-type: application/zip");
88         
header("content-size: "strlen($zfile));
89         
header('Content-Disposition: attachment; filename="Image.zip"');
90         echo 
$zfile;
91     }
92     else
93     {
94         
$file file_get_contents($file);
95         
$types = array('rtf' => 'text/enriched''txt' => 'text/plain''html' => 'text/html''jpg' => 'image/jpeg');
96         
header("content-type: ".$types[$globali[type]]);
97         
header("content-size: "strlen($file));
98         
header('Content-Disposition: attachment; filename="Image.'.$globali[type].'"');    
99         echo 
$file;
100     }
101     die;
102 }
103 if ( 
$globali[action] == "email" && $globali[send_email] )
104 {
105     
$file TMP_DIR $globali[base_name] . "." .  $globali[type];
106     if (
filesize($file) > 300*1024 && $globali[type] != "jpg")
107     {
108         
$file file_get_contents($file); 
109
110         
$zipfile = new Ziplib;
111         
$zipfile->zl_add_file($file,"image.".$globali[type],"g9");    
112
113         
$file $zipfile->zl_pack("Downloaded from http://pic2text.divxmania.it");
114         
$type "application/zip";
115         
$globali[type] = "zip";
116     }
117     else
118     {
119         
$file file_get_contents($file);
120         
$types = array('rtf' => 'text/enriched''txt' => 'text/plain''html' => 'text/html''jpg' => 'image/jpeg');
121         
$type $types[$globali[type]];
122     }
123
124     
$globali[contents] = stripslashes($globali[contents]);
125
126     
$subject "Ascii Art Image";
127     
$message $globali[contents]."\n\n________________________________________________________________________\n\nMessaggio inviato con Mail@Divxmania v3\n\nCrea la tua email gratis su http://mail.divxmania.it/\n\n 2005 - http://www.divxmania.it/ - Powered by http://www.nectarine.info ";
128     
$message_html '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
129     <HTML>
130     <HEAD>
131         <META NAME="Author" CONTENT="ceres">
132         </HEAD>
133             <BODY>
134             <P>'
.nl2br(HTMLEncode($globali[contents])).'
135             </P>
136             <PRE>
137 ________________________________________________________________________
138
139 Messaggio inviato con Mail@Divxmania v3
140
141 Crea la tua email gratis su <a href="http://mail.divxmania.it/">http://mail.divxmania.it/</a>
142
143  2005 - <a href="http://www.divxmania.it/">http://www.divxmania.it/</a> - Powered by <a href="http://www.nectarine.it">http://www.nectarine.it</a>
144             </PRE>
145             </BODY>
146         </HTML>'
;
147
148     
$mail->From     $globali[from_address];
149     
$mail->FromName $globali[from_name];
150     
$mail->AddAddress($globali[to_address],$globali[to_name]); 
151     
$mail->AddReplyTo($globali[from_address],"");
152     
$mail->IsHTML(true);                            
153     
$mail->Subject  =  $subject;
154     
$mail->Body     =  $message_html;
155     
$mail->AltBody  =  $message;
156
157     
$mail->AddStringAttachment($file"Image.".$globali[type], "base64"$type);
158
159     if (
$mail->Send())
160     {
161         
$err '<span style="color:green">'.$lang['mail_sent'].'</span>';
162     }
163     else
164     {
165         
$err '<span style="color:red">'.$lang['mail_notsent'].'<br />'.$mail->ErrorInfo.'</span>';
166     }
167
168     
$out '
169               <table border="0" width="200" cellspacing="0" cellpadding="3">
170                 <tr>
171                   <td width="100%" bgcolor="#8AB9FF">
172                     <p align="center"><b>'
.$lang['send_win'].'</b></td>
173
174                 </tr>
175                 <tr>
176                   <td width="100%" bgcolor="#F7F3F3" style="border-left: 1px solid #8AB9FF; border-right: 1px solid #8AB9FF; border-bottom: 1px solid #8AB9FF">
177                     <nobr>
178                     <p class="text" style="margin: 5" align="center">
179                         '
.$err.'
180                     </p>
181                     <p class="text" style="margin: 5" align="center">
182                         <a href="javascript:window.close();">'
.$lang['close_win'].'</a>
183                     </p>                    
184                     </nobr>
185               </td>
186                 </tr>
187               </table>'
;
188     
$parser->load_template('convert');
189     
190     
$variabili = array(
191     
192     
t_result        => $out,
193     
194     );
195     
196     
$parser->parse($variabili);
197     
show_footer();
198     
199     
$parser->print_page();
200     die;
201
202 }
203
204
205
206
207 if (
$globali['start_conversion'])
208 {
209     
convert_picture();
210 }
211 else
212 {
213     
show_upload($globali['action']);
214 }
215
216
217
//Functions definitions
218
219
function show_upload($mode$error "")
220 {
221     global 
$globali$lang$parser;
222
223     
//Check for supported image types
224     
$supported $lang[supported];
225     if (
imagetypes() & IMG_GIF$supported .= "GIF, ";
226     if (
imagetypes() & IMG_JPG$supported .= "JPEG, ";
227     if (
imagetypes() & IMG_PNG$supported .= "PNG, ";
228     
$supported .= "BMP, ";
229     if (
imagetypes() & IMG_WBMP$supported .= "WBMP, ";
230     if (
imagetypes() & IMG_XPM$supported .= "XPM, ";
231
232     
233     
$sup rtrim($supported", ");
234
235     
$parser->load_template($mode);
236
237     
$variabili = array(
238
239     
t_result        => $imagetxt,
240     
t_error            => $error,
241     
t_supported        => $sup,
242
243     
t_selcol         => $lang[selcol],
244     
t_immagine        => $lang[immagine],
245     
t_aa            => $lang[aa],
246     
t_aa_spiega        => $lang[aa_s],
247     
t_bw            => $lang[bw],
248     
t_neg            => $lang[neg],
249     
t_bgcolor        => $lang[sfondo],
250     
t_txtcolor        => $lang[ctext],
251     
t_picker        => sprintf($lang[picker], "pick1129902630"),
252     
t_picker1        => sprintf($lang[picker], "pick1129902631"),
253     
t_lettere        => $lang[ctu],
254     
t_custom_chars        => $lang[custom_chars],
255     
t_random        => $lang[random],
256     
t_dim            => $lang[dim],
257     
t_dim_block        => $lang[dim_block],
258     
t_d1            => $lang[d1],
259     
t_d2            => $lang[d2],
260     
t_d3            => $lang[d3],
261     
t_d4            => $lang[d4],
262     
t_d5            => $lang[d5],
263     
t_d6            => $lang[d6],
264     
t_d7            => $lang[d7],
265     
t_orwidth        => $lang[orwidth],
266     
t_width            => $lang[width],
267     
t_wspiega        => $lang[wspiega],
268     
t_wspiega1        => $lang[wspiega1],
269     
t_output        => $lang[output],
270     
t_jpg            => $lang[jpg],
271     
t_upload        => $lang[upload],
272     
t_url            => $lang[url],
273     
t_on_pc            => $lang[on_pc],
274     
275     
276     );
277
278     
$parser->parse($variabili);
279 }
280
281 function 
convert_picture()
282 {
283     global 
$globali$lang$parser$font_corr$rtf;
284
285     
$conv_mode $globali['action'];        //Valid: text | ascii | table
286     
$output_mode $globali['output_type'];        //Valid: text | image
287     
$char_to_use $globali['lettere'];        //Valid: Any ascii string
288     
$random_mode $globali['random'];        //Boolean
289     
$antialias $globali['AA'];            //Boolean
290     
$negative $globali['NEG'];            //Boolean
291     
$blackwhite $globali['BN']    ;        //Boolean
292     
$dim $globali['dimchar'];            //Integer, Valid: 1...10 | 13 | 16 | 20
293     
$txt_color $globali['txtcolor'];        //Hex color code, without starting "#"
294     
$back_color $globali['sfondo'];        //Hex color code, without starting "#"
295     
$width_override $globali['no_override'];    //Boolean
296     
$width = ($globali['width'] < 401) ? $globali['width'] : 400;        //Integer, Valid: 1...400
297
298     
if ($globali[source] == "url")
299     {
300         
$_FILES['userfile']['tmp_name'] = $globali[userfile];
301         
$url strrev($globali[userfile]);
302         
$t_url explode("/"$url);
303         
$_FILES['userfile']['name'] = strrev($t_url[0]);
304     }
305
306     
$im open_save_image($_FILES['userfile']['tmp_name']);
307     if ( 
$im == FALSE )
308     {
309         
show_upload($globali['action'], $lang[error_image]);
310         return 
false;
311     }
312     
313     
/**************************************
314     Don't change anything below this line!
315     **************************************/
316     
if ($conv_mode != "puzzle")
317     {
318         if (
$width_override == true)
319         {
320             
$ystep $dim;
321             
$xstep $dim/$font_corr[$dim];
322         } else {
323             
$xstep imagesx($im)/$width;
324             
$ystep = (imagesx($im)/$width)*$font_corr[$dim];
325         }
326         
Create_Color_Matrix($matrix$im$ystep$xstep$antialias$blackwhite$negative);
327     
328         if (
$conv_mode != "table")
329         {
330             
$rtf->setPaperOrientation(1);
331             
$rtf->setDefaultFontFace(0);
332             
$rtf->setDefaultFontSize(round($dim/96*72)*2);
333             
$rtf->setAuthor("CereS");
334             
$rtf->setOperator("ceres@divxmania.it");
335             
$rtf->setTitle("Image Output");
336             
$rtf->addBGColor("#".$back_color);
337             
$rtf->addColour("#".$txt_color);
338
339             
$rtf_corr = array(
340             
=> 1.6,
341             
=> 1.6,
342             
=> 1.6,
343             
10 => 1.6,
344             
13 => 1.6,
345             
16 => 1.6,
346             
20 => 1.6
347             
);
348
349             
$ys round(ceil($dim/96*72) * 20 count($matrix) + 400);
350             
$xs round(ceil($dim/96*72) * 20 count($matrix[0]) / $rtf_corr[$dim] + 400);
351             
$rtf->customPaperSize($xs,$ys);
352         }
353     
354         if (
$conv_mode == "text")
355             
$out Create_HTML_image($matrix$dim$output_mode$back_color);
356         elseif (
$conv_mode == "ascii")
357             
$out Create_ASCII_image($matrix$dim$output_mode$txt_color$back_color);
358         else
359             
$out Create_TABLE_image($matrix$dim);
360     }
361     else
362     {
363         
$x imagesx($im);
364         
$y imagesy($im);
365
366         
$bl_size $dim;
367         
368         
$x_size $x round($x $bl_size);
369         
$y_size $y round($y $bl_size);
370     
371         
$tc imagecolorallocate ($im133133133);
372         
$tc1 imagecolorallocate ($im333333);
373         
374         
$low "low"
375         for (
$b $y_size$b $y$b+=$y_size)
376         {
377             for (
$a 0$a $x$a += $x_size)
378             {
379                 
draw_puzzle($im$x_size$a$x_size/3$b-$x_size/3$tc$tc1$low"oriz");
380             }
381             (
$low == "low") ? $low "nolow" $low "low"
382         }
383         for (
$b 0$b $y$b+=$y_size)
384         {
385             for (
$a $x_size$a $x-$x_size/3$a += $x_size)
386             {
387                 
draw_puzzle($im$y_size$b$y_size/3$a-$x_size/3$tc$tc1$low"ver");
388                 (
$low == "low") ? $low "nolow" $low "low"
389             }
390             
391         }
392         
imagelinethick($im1,1,$x+1,1,$tc,3); // - sopra
393         
imagelinethick($im1,$y-3,$x+1,$y-3,$tc,3); // - sotto
394         
imagelinethick($im1,0,1,$y,$tc,3); // | sx
395         
imagelinethick($im$x-3,0,$x-3,$y,$tc,3); // | dx
396         
397         
imageline($im0,0,$x,0,$tc1); // - sopra
398         
imageline($im0,$y-1,$x,$y-1,$tc1); // - sotto
399         
imageline($im0,0,0,$y,$tc1); // | sx
400         
imageline($im$x-1,0,$x-1,$y,$tc1); // | dx
401
402         
$out $im;     
403     
404     }
405     
$tmp_name md5(time());
406         
407     if (
$conv_mode != "table" && $output_mode != "image")
408     {
409         
$rtf_file_data $rtf->GetDocument();
410         
$res fopen(TMP_DIR $tmp_name ".rtf" "w");
411         @
fwrite($res$rtf_file_data);
412         
$dl_rtf_td '<td><img src="img/rtf.gif" title="Rich Text Format" border="0"></td>';
413         
$dl_rtf_radio '<td><input type="radio" name="type" value="rtf"></td>';
414     }
415     if (
$conv_mode == "ascii" && $output_mode != "image")
416     {
417         
$txt_data str_replace("<br />"""$out);
418         
$txt_data str_replace("</nobr>"""$txt_data);
419         
$txt_data str_replace("&nbsp;"" "$txt_data);
420         
$txt_data preg_replace("|<nobr [^>]*?>\n|"""$txt_data);
421         
$res fopen(TMP_DIR $tmp_name ".txt" "w");
422         @
fwrite($res$txt_data);
423         
$dl_txt_td '<td><img src="img/txt.gif" title="Plain Text" border="0"></td>';
424         
$dl_txt_radio '<td><input type="radio" name="type" value="txt"></td>';
425     }
426         
427     if (
$output_mode == "image"
428     {
429         
//Write image to a temp folder
430         
$tname $tmp_name ".jpg";
431         
imagejpeg($outTMP_DIR $tname);  
432         
$out "<img src='tmp/$tname'>";
433
434         
$out .= '
435         <br /><br /><br />
436               <table border="0" width="200" cellspacing="0" cellpadding="3">
437                 <tr>
438                   <td width="100%" bgcolor="#8AB9FF">
439                     <p align="center"><b>DOWNLOAD</b></td>
440
441                 </tr>
442                 <tr>
443                   <td width="100%" bgcolor="#F7F3F3" style="border-left: 1px solid #8AB9FF; border-right: 1px solid #8AB9FF; border-bottom: 1px solid #8AB9FF">
444                     <p class="text" style="margin: 5" align="center">
445                         <form method="post" name="downloader" action="'
.SELF.'?page=image&action=download">
446                         <table align="center">
447                         <tr align="center">
448                             <td><input type="image" name="picture" src="img/image.gif" title="JPEG Image" border="0"></td>
449                         </tr>
450             </table>
451             <input type="hidden" name="start_download" value="1">
452             <input type="hidden" name="type" value="jpg">
453             <input type="hidden" name="base_name" value="'
.$tmp_name.'">
454             </form>
455                     </p>
456                     <p class="text" align=center>
457             <nobr><b>'
.$lang[donotlink].'</b><br />'.$lang[deletein4h].'</nobr>
458             </p>
459               </td>
460                 </tr>
461               </table>        
462         '
;
463         
464         
$out .= '
465         <br /><br /><br />
466               <table border="0" width="400" cellspacing="0" cellpadding="3">
467                 <tr>
468                   <td width="100%" bgcolor="#8AB9FF">
469                     <p align="center"><b>'
.$lang['mail_send'].'</b></td>
470
471                 </tr>
472                 <tr>
473                   <td width="100%" bgcolor="#F7F3F3" style="border-left: 1px solid #8AB9FF; border-right: 1px solid #8AB9FF; border-bottom: 1px solid #8AB9FF">
474                     <p class="text" style="margin: 5" align="center">
475                         <form method="post" name="email" action="'
.SELF.'?page=image&action=email" target="_blank">
476             <table align="center">
477             <tr>
478                 <td>'
.$lang['mail_a'].':</td>
479                 <td>
480                     <input type="text" name="to_name" value="'
.$lang['mail_nome'].'" size="10">
481                     <input type="text" name="to_address" value="abcd@example.com" size="25">
482                 </td>
483             </tr>
484             <tr>
485                 <td>'
.$lang['mail_da'].':</td>
486                 <td>
487                     <input type="text" name="from_name" value="'
.$lang['mail_nome'].'" size="10">
488                     <input type="text" name="from_address" value="abcd@example.com" size="25">
489                 </td>
490             </tr>
491             <tr>
492                 <td colspan=2>'
.$lang['mail_testo'].':<br>
493                     <textarea cols=40 rows=8 name="contents">'
.$lang['mail_content'].'</textarea>
494                 </td>
495             </tr>
496             </table>
497             <input type="hidden" name="type" value="jpg">
498             <input type="hidden" name="base_name" value="'
.$tmp_name.'">
499             <center><input type="submit" name="send_email" value="'
.$lang['mail_submit'].'"></center>
500             </form>
501                     </p>
502              </td>
503                 </tr>
504               </table>        
505         '
;                
506     } 
507     
508
509     
$out '<!--
510         ##############################################
511         #              Generated with:               #
512         #           Divxmania Artworks 2.0           #
513         ##############################################
514         
515         Filename:     '
.$_FILES["userfile"]["name"].'
516         Date:         '
.date("D j M Y G:i:s").'
517         Requested by: '
.$_SERVER["REMOTE_ADDR"].'
518         
519         ##############################################
520         #    This script is rated: USELESS!!! :):    #
521         ##############################################
522         !-->
523         '
.$out;
524         
525     if (
$output_mode != "image")
526     {
527         
$res fopen(TMP_DIR $tmp_name ".html" "w");
528         @
fwrite($res$out);
529     
530         
$out .= '
531         <br /><br /><br />
532               <table border="0" width="200" cellspacing="0" cellpadding="3">
533                 <tr>
534                   <td width="100%" bgcolor="#8AB9FF">
535                     <p align="center"><b>DOWNLOAD</b></td>
536
537                 </tr>
538                 <tr>
539                   <td width="100%" bgcolor="#F7F3F3" style="border-left: 1px solid #8AB9FF; border-right: 1px solid #8AB9FF; border-bottom: 1px solid #8AB9FF">
540                     <p class="text" style="margin: 5" align="center">
541                         <form method="post" name="downloader" action="'
.SELF.'?page=image&action=download">
542                         <table align="center">
543                         <tr align="center">
544                             <td><img src="img/html.gif" title="HyperText Markup Language" border="0"></td>
545                             '
.$dl_rtf_td.'
546                             '
.$dl_txt_td.'
547                         </tr>
548                         <tr align="center">
549                             <td><input type="radio" name="type" value="html" checked="checked"></td>
550                             '
.$dl_rtf_radio.'
551                             '
.$dl_txt_radio.'
552             </tr>
553             </table>
554             <input type="hidden" name="base_name" value="'
.$tmp_name.'">
555             <center><input type="submit" name="start_download" value="Download"></center>
556             </form>
557                     </p>
558                     <p class="text" align=center>
559             <nobr>'
.$lang['file_300'].'</nobr>
560             </p>                    
561               </td>
562                 </tr>
563               </table>        
564         '
;
565         
566         
$out .= '
567         <br /><br /><br />
568               <table border="0" width="400" cellspacing="0" cellpadding="3">
569                 <tr>
570                   <td width="100%" bgcolor="#8AB9FF">
571                     <p align="center"><b>'
.$lang['mail_send'].'</b></td>
572
573                 </tr>
574                 <tr>
575                   <td width="100%" bgcolor="#F7F3F3" style="border-left: 1px solid #8AB9FF; border-right: 1px solid #8AB9FF; border-bottom: 1px solid #8AB9FF">
576                     <p class="text" style="margin: 5" align="center">
577                         <form method="post" name="email" action="'
.SELF.'?page=image&action=email" target="_blank">
578                         <table align="center">
579                         <tr align="center">
580                             <td><img src="img/html.gif" title="HyperText Markup Language" border="0"></td>
581                             '
.$dl_rtf_td.'
582                             '
.$dl_txt_td.'
583                         </tr>
584                         <tr align="center">
585                             <td><input type="radio" name="type" value="html" checked="checked"></td>
586                             '
.$dl_rtf_radio.'
587                             '
.$dl_txt_radio.'
588             </tr>
589             </table>
590             <table align="center">
591             <tr>
592                 <td>'
.$lang['mail_a'].':</td>
593                 <td>
594                     <input type="text" name="to_name" value="'
.$lang['mail_nome'].'" size="10">
595                     <input type="text" name="to_address" value="abcd@example.com" size="25">
596                 </td>
597             </tr>
598             <tr>
599                 <td>'
.$lang['mail_da'].':</td>
600                 <td>
601                     <input type="text" name="from_name" value="'
.$lang['mail_nome'].'" size="10">
602                     <input type="text" name="from_address" value="abcd@example.com" size="25">
603                 </td>
604             </tr>
605             <tr>
606                 <td colspan=2>'
.$lang['mail_testo'].':<br>
607                     <textarea cols=40 rows=8 name="contents">'
.$lang['mail_content'].'</textarea>
608                 </td>
609             </tr>
610             </table>
611             <input type="hidden" name="base_name" value="'
.$tmp_name.'">
612             <center><input type="submit" name="send_email" value="'
.$lang['mail_submit'].'"></center>
613             </form>
614                     </p>
615                     <p class="text" align=center>
616             <nobr>'
.$lang['file_300'].'</nobr>
617             </p>                    
618               </td>
619                 </tr>
620               </table>        
621         '
;        
622         
623         
624     
625     }        
626     
627     
$parser->load_template('convert');
628
629     
$variabili = array(
630
631     
t_result        => $out,
632
633     );
634
635     
$parser->parse($variabili);
636
637
638 }
639 function 
Create_HTML_image($matrix$dim$output "html"$bgcolor)
640 {
641     global 
$font_corr$rtf;
642     
$y_dim count($matrix);
643     
$x_dim count($matrix[0]);
644     
$ty $dim-2;
645     
$tx 0;
646     if (
$output == "image")
647     {
648         
$ret_img imagecreatetruecolor($x_dim $dim/$font_corr[$dim], $y_dim $dim);
649         
$r hexdecsubstr$bgcolor1) );
650         
$g hexdecsubstr$bgcolor3) );
651         
$b hexdecsubstr$bgcolor5) );
652         
$bg imagecolorallocate($ret_img$r$g$b);
653         
imagefill($ret_img1,1,$bg);
654     }        
655     
656     
$HTML "<nobr>\n<span style=\"font-family:'Courier New', Courier, monospace; font-size: $dim; line-height: {$dim}px; letter-spacing: 0px; color: #000000; background-color: $bgcolor;\">\n";
657     
658     for(
$y 0$y $y_dim$y++)
659     {
660         
$tx 0;
661         
$x_array $matrix[$y];
662         for(
$x 0$x count($x_array); $x++)
663         {
664             
$vals $x_array[$x];
665             
$hexcol colorHEX($vals[red], $vals[green], $vals[blue]);
666             if (
$x == 0)
667             {
668                 
$HTML .= "<span style='color: #$hexcol;'>$vals[char]";
669                 
$rtf->addColour("#".$hexcol);
670                 (
$vals[char] == "&nbsp;") ? $rtf->addText(" ") : $rtf->addText($vals[char]);
671             }
672             elseif (
$prev_col == $hexcol)
673             {
674                 
$HTML .= $vals[char];
675                 (
$vals[char] == "&nbsp;") ? $rtf->addText(" ") : $rtf->addText($vals[char]);
676             }
677             else
678             {
679                 
$HTML .= "</span><span style='color: #$hexcol;'>$vals[char]";
680                 
$rtf->addColour("#".$hexcol);
681                 (
$vals[char] == "&nbsp;") ? $rtf->addText(" ") : $rtf->addText($vals[char]);
682             }
683             
684             if (
$output == "image")
685                 
imagettftext($ret_img$dim/96*720$tx$ty"0x".$hexcolFONT, ($vals[char] == "&nbsp;") ? " " $vals[char]);
686             
687             (int) 
$tx += $dim/$font_corr[$dim];
688             
$prev_col $hexcol;
689             
690         }
691         
$HTML .= "</span><br />\n";
692         
$rtf->addText("<BR>");
693         
$prev_col "";
694         
$ty += $dim;
695     }
696     
$HTML .= "</span>\n</nobr>";
697     if (
$output == "image")    
698         return 
$ret_img;
699     else
700         return 
$HTML;
701 }
702 function 
Create_TABLE_image($matrix$dim)
703 {
704     global 
$font_corr;
705     
$y_dim count($matrix);
706     
$x_dim count($matrix[0]);
707
708     
$x_size $dim/$font_corr[$dim];
709     
$prev_col "";
710     
$cspan 1;
711     
712     
$HTML "<table width=".$x_dim*$x_size." cellspacing=0 cellpadding=0>\n";
713     
714     for(
$y 0$y $y_dim$y++)
715     {
716         
$x_array $matrix[$y];
717         
$HTML .= "<TR height=\"$dim\">\n";
718
719         for(
$x 0$x count($x_array); $x++)
720         {
721             
$vals $x_array[$x];
722             
$hexcol colorHEX($vals[red], $vals[green], $vals[blue]);
723             if (
$prev_col == $hexcol)
724                 
$cspan++;
725             else
726             {
727                 
$HTML .= "    <TD colspan='$cspan' width='$x_size' style='background-color: #$hexcol;'></TD>\n";
728                 
$cspan 1;
729             }
730                 
731             
$prev_col $hexcol;
732         }
733         
$HTML .= "</TR>\n";
734         
$cspan 1;
735         
$prev_col "";
736     }
737     
$HTML .= "\n</table>";
738     return 
$HTML;
739 }
740
741 function 
Create_ASCII_image($matrix$dim$output "html"$color$bgcolor)
742 {
743     global 
$font_corr$rtf;
744     
$y_dim count($matrix);
745     
$x_dim count($matrix[0]);
746     
$ty $dim-2;
747     
$tx 0;
748     
749     if (
$output == "image")
750     {
751         
$ret_img imagecreatetruecolor($x_dim $dim/$font_corr[$dim], $y_dim $dim);
752         
$r hexdecsubstr$bgcolor1) );
753         
$g hexdecsubstr$bgcolor3) );
754         
$b hexdecsubstr$bgcolor5) );
755         
$bg imagecolorallocate($ret_img$r$g$b);
756         
imagefill($ret_img1,1,$bg);
757         
758         
$r hexdecsubstr$color1) );
759         
$g hexdecsubstr$color3) );
760         
$b hexdecsubstr$color5) );
761         
$fg imagecolorallocate($ret_img$r$g$b);
762     }    
763     
764     
$HTML "<nobr align=left style=\"font-family:'Courier New', Courier, monospace; font-size: $dim; line-height: {$dim}px; letter-spacing: 0px; color: $color; background-color: $bgcolor;\">\n";
765     
766     for(
$y 0$y $y_dim$y++)
767     {
768         
$tx 0;
769         
$x_array $matrix[$y];
770         for(
$x 0$x count($x_array); $x++)
771         {
772             
$vals $x_array[$x];
773             
$HTML .= $vals[char];
774             
775             (
$vals[char] == "&nbsp;") ? $rtf->addText(" ") : $rtf->addText($vals[char]);
776             
777             if (
$output == "image")
778                 
imagettftext($ret_img$dim/96*720$tx$ty$fgFONT, ($vals[char] == "&nbsp;") ? " " $vals[char]);
779             
780             (int) 
$tx += $dim/$font_corr[$dim];
781             
782         }
783         
$HTML .= "<br />\n";
784         
$rtf->addText("<BR>");        
785         
$ty += $dim;
786     }
787     
$HTML .= "</nobr>";
788     if (
$output == "image")    
789         return 
$ret_img;
790     else
791         return 
$HTML;
792 }
793 function 
colorHEX ($r$g$b) {
794     
//The next 3 lines are used to compensate hex values 0 to F (0 to 15) adding an initial 0 (00 to 0F)
795     
($r >= 16) ? $red dechex($r) : $red "0".dechex($r);
796     (
$g >= 16) ? $green dechex($g) : $green "0".dechex($g);
797     (
$b >= 16) ? $blue dechex($b) : $blue "0".dechex($b);
798     
$color $red.$green.$blue;
799     return 
$color;
800 }
801
/*****************************
802 * Function Create_Color_Matrix
803 *****************************/
804
function Create_Color_Matrix(&$matrix$im$ystep$xstep$aa false$bn false$inv false)
805 {
806     
$row 0;
807     for (
$y 0$y imagesy($im); $y += $ystep)
808     {
809         
$col 0;
810         for (
$x 0$x imagesx($im); $x += $xstep)
811         {
812             if (
$aa == false)
813             {
814                 
$rgb imagecolorat($im$x$y);
815                 
$color[red] = ($rgb >> 16) & 255;
816                 
$color[green] = ($rgb >> 8) & 255;
817                 
$color[blue] = $rgb 255;
818             }
819             else
820             {
821                 
$color Get_AntiAlias($im$x$y$ystep$xstep);
822             }
823             if (
$inv == true)
824             {
825                 
$color[red] = 255 $color[red];
826                 
$color[green] = 255 $color[green];
827                 
$color[blue] = 255 $color[blue];
828             }
829             if (
$bn == true)
830             {
831                 
$bw round((222*$color[red]+707*$color[green]+71*$color[blue])/1000);
832                 
$color[red] = $bw;
833                 
$color[green] = $bw;
834                 
$color[blue] = $bw;
835             }
836             
$matrix[$row][$col] = $color;
837             
$matrix[$row][$col][char] = Set_Char($color$col+$row);
838             
$col++;
839         }
840         
$row++;
841     }
842 }
843 function 
Get_AntiAlias(&$im$x$y$ystep$xstep)
844 {
845     
$r $g $b 0;
846     for (
$ay $y$ay <= $y+$ystep$ay++)
847     {
848         if (
$ay imagesy($im))
849         {
850             for (
$ax $x$ax <= $x+$xstep$ax++)
851             {
852                 if (
$ax imagesx($im))
853                 {
854                     
$rgb imagecolorat($im$ax$ay);
855                     
$r += ($rgb >> 16) & 255;
856                     
$g += ($rgb >> 8) & 255;
857                     
$b += $rgb 255;
858                     
$pixels++;
859                 }
860             }
861         }
862     }
863     (int) 
$r $r $pixels;
864     (int) 
$g $g $pixels;
865     (int) 
$b $b $pixels;
866     return array(
red=>$rgreen=>$gblue=>$b);
867 }
868 function 
Set_Char($color ""$nnn 0)
869 {
870     global 
$conv_mode$char_to_use$random_mode$custom_chars;
871     
$ascii_array ' .\'",*!(=7CJ3%A5#@WM';
872     switch (
$conv_mode)
873     {
874         case 
"table":
875             
$char "";
876             break;
877         case 
"ascii":
878             
$value 23 floor($color[red] / 11);
879             
$char = ($value == 0) ? "&nbsp;" $ascii_array{$value};
880             break;
881         default:
882             if (
$custom_chars == true)
883             {
884                 if (
$random_mode == true)
885                 {
886                     
$char $char_to_use{mt_rand(0strlen($char_to_use)-1)};
887                 }
888                 else
889                 {
890                     
$char $char_to_use{$nnn strlen($char_to_use)};
891                 }
892                 break;
893             }
894             else
895             {
896                 
$bw round((222*$color[red]+707*$color[green]+71*$color[blue])/1000);
897                 
$value 23 floor($bw 11);
898                 
$char = ($value == 0) ? "&nbsp;" $ascii_array{$value};
899                 break;            
900             }
901     }
902     return 
$char;
903
904 }
905
906 function 
open_save_image($input$mode=1$output="")
907 {
908     
$types = array(    => "GIF"=> "JPG"=> "PNG"
909             
=> "SWF"=> "PSD"=> "BMP",
910             
=> "TIFF(intel byte order)"=> "TIFF(motorola byte order)"
911             
=> "JPC"10 => "JP2"11 => "JPX"12 => "JB2"
912             
13 => "SWC"14 => "IFF"15 => "WBMP"16 => "XBM");
913     switch (
$mode)
914     {
915         
//Open an image
916         
case 1:
917             list (
$a$b$c) = getimagesize($input);
918             
$type $types[$c];
919             switch (
$type)
920             {
921                 
// GD supported types
922                 
case "GIF":
923                 case 
"JPG":
924                 case 
"PNG":
925                 case 
"WBMP":
926                 case 
"XBM":
927                     
$im = @imagecreatefromstring(file_get_contents($input));
928                     if (
$im == false)
929                         
$error_code 1;
930                     break;
931                 case 
"BMP":
932                     
$im imagecreatefrombmp($input);
933                     if (
$im == false)
934                         
$error_code 1;
935
936                     break;
937                 default:
938                     
$error_code 1;
939             }
940             if(
$error_code != 1)
941                 return 
$im;
942             else
943                 return 
FALSE;
944
945         
//Save an image
946         
case 2:
947             if(
imagejpeg($input$output100))
948                 return 
TRUE;
949             else
950                 return 
FALSE;
951
952     }
953 }
954
955
/*
956 *------------------------------------------------------------
957 *                   BMP Image functions
958 *------------------------------------------------------------
959 *                      By JPEXS
960 */
961
962
963
964
965 /*
966 *------------------------------------------------------------
967 *                    ImageBMP
968 *------------------------------------------------------------
969 *            - Creates new BMP file
970 *
971 *         Parameters:  $img - Target image
972 *                      $file - Target file to store
973 *                            - if not specified, bmp is returned
974 *
975 *           Returns: if $file specified - true if OK
976                      if $file not specified - image data
977 */
978
function imagebmp($img,$file="",$RLE=0)
979 {
980
981
982
$ColorCount=imagecolorstotal($img);
983
984
$Transparent=imagecolortransparent($img);
985
$IsTransparent=$Transparent!=-1;
986
987
988 if(
$IsTransparent$ColorCount--;
989
990 if(
$ColorCount==0) {$ColorCount=0$BitCount=24;};
991 if((
$ColorCount>0)and($ColorCount<=2)) {$ColorCount=2$BitCount=1;};
992 if((
$ColorCount>2)and($ColorCount<=16)) { $ColorCount=16$BitCount=4;};
993 if((
$ColorCount>16)and($ColorCount<=256)) { $ColorCount=0$BitCount=8;};
994
995
996                 
$Width=imagesx($img);
997                 
$Height=imagesy($img);
998
999                 
$Zbytek=(4-($Width/(8/$BitCount))%4)%4;
1000
1001                 if(
$BitCount<24$palsize=pow(2,$BitCount)*4;
1002
1003                 
$size=(floor($Width/(8/$BitCount))+$Zbytek)*$Height+54;
1004                 
$size+=$palsize;
1005                 
$offset=54+$palsize;
1006
1007                 
// Bitmap File Header
1008                 
$ret 'BM';                        // header (2b)
1009                 
$ret .= int_to_dword($size);        // size of file (4b)
1010                 
$ret .= int_to_dword(0);        // reserved (4b)
1011                 
$ret .= int_to_dword($offset);        // byte location in the file which is first byte of IMAGE (4b)
1012                 // Bitmap Info Header
1013                 
$ret .= int_to_dword(40);        // Size of BITMAPINFOHEADER (4b)
1014                 
$ret .= int_to_dword($Width);        // width of bitmap (4b)
1015                 
$ret .= int_to_dword($Height);        // height of bitmap (4b)
1016                 
$ret .= int_to_word(1);        // biPlanes = 1 (2b)
1017                 
$ret .= int_to_word($BitCount);        // biBitCount = {1 (mono) or 4 (16 clr ) or 8 (256 clr) or 24 (16 Mil)} (2b)
1018                 
$ret .= int_to_dword($RLE);        // RLE COMPRESSION (4b)
1019                 
$ret .= int_to_dword(0);        // width x height (4b)
1020                 
$ret .= int_to_dword(0);        // biXPelsPerMeter (4b)
1021                 
$ret .= int_to_dword(0);        // biYPelsPerMeter (4b)
1022                 
$ret .= int_to_dword(0);        // Number of palettes used (4b)
1023                 
$ret .= int_to_dword(0);        // Number of important colour (4b)
1024                 // image data
1025
1026                 
$CC=$ColorCount;
1027                 
$sl1=strlen($ret);
1028                 if(
$CC==0$CC=256;
1029                 if(
$BitCount<24)
1030                    {
1031                     
$ColorTotal=imagecolorstotal($img);
1032                      if(
$IsTransparent$ColorTotal--;
1033
1034                      for(
$p=0;$p<$ColorTotal;$p++)
1035                      {
1036                       
$color=imagecolorsforindex($img,$p);
1037                        
$ret.=inttobyte($color["blue"]);
1038                        
$ret.=inttobyte($color["green"]);
1039                        
$ret.=inttobyte($color["red"]);
1040                        
$ret.=inttobyte(0); //RESERVED
1041                      
};
1042
1043                     
$CT=$ColorTotal;
1044                   for(
$p=$ColorTotal;$p<$CC;$p++)
1045                        {
1046                       
$ret.=inttobyte(0);
1047                       
$ret.=inttobyte(0);
1048                       
$ret.=inttobyte(0);
1049                       
$ret.=inttobyte(0); //RESERVED
1050                      
};
1051                    };
1052
1053
1054 if(
$BitCount<=8)
1055 {
1056
1057  for(
$y=$Height-1;$y>=0;$y--)
1058  {
1059   
$bWrite="";
1060   for(
$x=0;$x<$Width;$x++)
1061    {
1062    
$color=imagecolorat($img,$x,$y);
1063    
$bWrite.=decbinx($color,$BitCount);
1064    if(
strlen($bWrite)==8)
1065     {
1066      
$retd.=inttobyte(bindec($bWrite));
1067      
$bWrite="";
1068     };
1069    };
1070
1071   if((
strlen($bWrite)<8)and(strlen($bWrite)!=0))
1072     {
1073      
$sl=strlen($bWrite);
1074      for(
$t=0;$t<8-$sl;$t++)
1075       
$sl.="0";
1076      
$retd.=inttobyte(bindec($bWrite));
1077     };
1078  for(
$z=0;$z<$Zbytek;$z++)
1079    
$retd.=inttobyte(0);
1080  };
1081 };
1082
1083 if((
$RLE==1)and($BitCount==8))
1084 {
1085  for(
$t=0;$t<strlen($retd);$t+=4)
1086   {
1087    if(
$t!=0)
1088    if((
$t)%$Width==0)
1089     
$ret.=chr(0).chr(0);
1090
1091    if((
$t+5)%$Width==0)
1092    {
1093      
$ret.=chr(0).chr(5).substr($retd,$t,5).chr(0);
1094      
$t+=1;
1095    }
1096    if((
$t+6)%$Width==0)
1097     {
1098      
$ret.=chr(0).chr(6).substr($retd,$t,6);
1099      
$t+=2;
1100     }
1101     else
1102     {
1103      
$ret.=chr(0).chr(4).substr($retd,$t,4);
1104     };
1105   };
1106   
$ret.=chr(0).chr(1);
1107 }
1108 else
1109 {
1110
$ret.=$retd;
1111 };
1112
1113
1114                 if(
$BitCount==24)
1115                 {
1116                 for(
$z=0;$z<$Zbytek;$z++)
1117                  
$Dopl.=chr(0);
1118
1119                 for(
$y=$Height-1;$y>=0;$y--)
1120                  {
1121                  for(
$x=0;$x<$Width;$x++)
1122                         {
1123                            
$color=imagecolorsforindex($img,ImageColorAt($img,$x,$y));
1124                            
$ret.=chr($color["blue"]).chr($color["green"]).chr($color["red"]);
1125                         }
1126                  
$ret.=$Dopl;
1127                  };
1128
1129                  };
1130
1131   if(
$file!="")
1132    {
1133     
$r=($f=fopen($file,"w"));
1134     
$r=$r and fwrite($f,$ret);
1135     
$r=$r and fclose($f);
1136     return 
$r;
1137    }
1138   else
1139   {
1140    echo 
$ret;
1141   };
1142 };
1143
1144
1145
/*
1146 *------------------------------------------------------------
1147 *                    ImageCreateFromBmp
1148 *------------------------------------------------------------
1149 *            - Reads image from a BMP file
1150 *
1151 *         Parameters:  $file - Target file to load
1152 *
1153 *            Returns: Image ID
1154 */
1155
1156
function imagecreatefrombmp($file)
1157 {
1158 global  
$CurrentBit$echoMode;
1159
1160
$f=fopen($file,"r");
1161
$Header=fread($f,2);
1162
1163 if(
$Header=="BM")
1164 {
1165  
$Size=freaddword($f);
1166  
$Reserved1=freadword($f);
1167  
$Reserved2=freadword($f);
1168  
$FirstByteOfImage=freaddword($f);
1169
1170  
$SizeBITMAPINFOHEADER=freaddword($f);
1171  
$Width=freaddword($f);
1172  
$Height=freaddword($f);
1173  
$biPlanes=freadword($f);
1174  
$biBitCount=freadword($f);
1175  
$RLECompression=freaddword($f);
1176  
$WidthxHeight=freaddword($f);
1177  
$biXPelsPerMeter=freaddword($f);
1178  
$biYPelsPerMeter=freaddword($f);
1179  
$NumberOfPalettesUsed=freaddword($f);
1180  
$NumberOfImportantColors=freaddword($f);
1181
1182 if(
$biBitCount<24)
1183  {
1184   
$img=imagecreate($Width,$Height);
1185   
$Colors=pow(2,$biBitCount);
1186   for(
$p=0;$p<$Colors;$p++)
1187    {
1188     
$B=freadbyte($f);
1189     
$G=freadbyte($f);
1190     
$R=freadbyte($f);
1191     
$Reserved=freadbyte($f);
1192     
$Palette[]=imagecolorallocate($img,$R,$G,$B);
1193    };
1194
1195
1196
1197
1198 if(
$RLECompression==0)
1199 {
1200    
$Zbytek=(4-ceil(($Width/(8/$biBitCount)))%4)%4;
1201
1202 for(
$y=$Height-1;$y>=0;$y--)
1203     {
1204      
$CurrentBit=0;
1205      for(
$x=0;$x<$Width;$x++)
1206       {
1207          
$C=freadbits($f,$biBitCount);
1208        
imagesetpixel($img,$x,$y,$Palette[$C]);
1209       };
1210     if(
$CurrentBit!=0) {freadbyte($f);};
1211     for(
$g=0;$g<$Zbytek;$g++)
1212      
freadbyte($f);
1213      };
1214
1215  };
1216 };
1217
1218
1219 if(
$RLECompression==1//$BI_RLE8
1220
{
1221
$y=$Height;
1222
1223
$pocetb=0;
1224
1225 while(
true)
1226 {
1227
$y--;
1228
$prefix=freadbyte($f);
1229
$suffix=freadbyte($f);
1230
$pocetb+=2;
1231
1232
$echoit=false;
1233
1234 if(
$echoit)echo "Prefix: $prefix Suffix: $suffix<BR>";
1235 if((
$prefix==0)and($suffix==1)) break;
1236 if(
feof($f)) break;
1237
1238 while(!((
$prefix==0)and($suffix==0)))
1239 {
1240  if(
$prefix==0)
1241   {
1242    
$pocet=$suffix;
1243    
$Data.=fread($f,$pocet);
1244    
$pocetb+=$pocet;
1245    if(
$pocetb%2==1) {freadbyte($f); $pocetb++;};
1246   };
1247  if(
$prefix>0)
1248   {
1249    
$pocet=$prefix;
1250    for(
$r=0;$r<$pocet;$r++)
1251     
$Data.=chr($suffix);
1252   };
1253  
$prefix=freadbyte($f);
1254  
$suffix=freadbyte($f);
1255  
$pocetb+=2;
1256  if(
$echoit) echo "Prefix: $prefix Suffix: $suffix<BR>";
1257 };
1258
1259 for(
$x=0;$x<strlen($Data);$x++)
1260  {
1261   
imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
1262  };
1263
$Data="";
1264
1265 };
1266
1267 };
1268
1269
1270 if(
$RLECompression==2//$BI_RLE4
1271
{
1272
$y=$Height;
1273
$pocetb=0;
1274
1275
/*while(!feof($f))
1276  echo freadbyte($f)._.freadbyte($f).><BR>";*/
1277
while(true)
1278 {
1279
//break;
1280
$y--;
1281
$prefix=freadbyte($f);
1282
$suffix=freadbyte($f);
1283
$pocetb+=2;
1284
1285
$echoit=false;
1286
1287 if(
$echoit)echo "Prefix: $prefix Suffix: $suffix<BR>";
1288 if((
$prefix==0)and($suffix==1)) break;
1289 if(
feof($f)) break;
1290
1291 while(!((
$prefix==0)and($suffix==0)))
1292 {
1293  if(
$prefix==0)
1294   {
1295    
$pocet=$suffix;
1296
1297    
$CurrentBit=0;
1298    for(
$h=0;$h<$pocet;$h++)
1299     
$Data.=chr(freadbits($f,4));
1300    if(
$CurrentBit!=0freadbits($f,4);
1301    
$pocetb+=ceil(($pocet/2));
1302    if(
$pocetb%2==1) {freadbyte($f); $pocetb++;};
1303   };
1304  if(
$prefix>0)
1305   {
1306    
$pocet=$prefix;
1307    
$i=0;
1308    for(
$r=0;$r<$pocet;$r++)
1309     {
1310     if(
$i%2==0)
1311      {
1312       
$Data.=chr($suffix%16);
1313      }
1314      else
1315      {
1316       
$Data.=chr(floor($suffix/16));
1317      };
1318     
$i++;
1319     };
1320   };
1321  
$prefix=freadbyte($f);
1322  
$suffix=freadbyte($f);
1323  
$pocetb+=2;
1324  if(
$echoit) echo "Prefix: $prefix Suffix: $suffix<BR>";
1325 };
1326
1327 for(
$x=0;$x<strlen($Data);$x++)
1328  {
1329   
imagesetpixel($img,$x,$y,$Palette[ord($Data[$x])]);
1330  };
1331
$Data="";
1332
1333 };
1334
1335 };
1336
1337
1338  if(
$biBitCount==24)
1339 {
1340  
$img=imagecreatetruecolor($Width,$Height);
1341  
$Zbytek=$Width%4;
1342
1343    for(
$y=$Height-1;$y>=0;$y--)
1344     {
1345      for(
$x=0;$x<$Width;$x++)
1346       {
1347        
$B=freadbyte($f);
1348        
$G=freadbyte($f);
1349        
$R=freadbyte($f);
1350        
$color=imagecolorexact($img,$R,$G,$B);
1351        if(
$color==-1$color=imagecolorallocate($img,$R,$G,$B);
1352        
imagesetpixel($img,$x,$y,$color);
1353       }
1354     for(
$z=0;$z<$Zbytek;$z++)
1355      
freadbyte($f);
1356    };
1357 };
1358 return 
$img;
1359
1360 };
1361
1362
1363
fclose($f);
1364
1365
1366 };
1367
1368
1369
1370
1371
1372
/*
1373 * Helping functions:
1374 *-------------------------
1375 *
1376 * freadbyte($file) - reads 1 byte from $file
1377 * freadword($file) - reads 2 bytes (1 word) from $file
1378 * freaddword($file) - reads 4 bytes (1 dword) from $file
1379 * freadlngint($file) - same as freaddword($file)
1380 * decbin8($d) - returns binary string of d zero filled to 8
1381 * RetBits($byte,$start,$len) - returns bits $start->$start+$len from $byte
1382 * freadbits($file,$count) - reads next $count bits from $file
1383 * RGBToHex($R,$G,$B) - convert $R, $G, $B to hex
1384 * int_to_dword($n) - returns 4 byte representation of $n
1385 * int_to_word($n) - returns 2 byte representation of $n
1386 */
1387
1388
function freadbyte($f)
1389 {
1390  return 
ord(fread($f,1));
1391 };
1392
1393 function 
freadword($f)
1394 {
1395  
$b1=freadbyte($f);
1396  
$b2=freadbyte($f);
1397  return 
$b2*256+$b1;
1398 };
1399
1400
1401 function 
freadlngint($f)
1402 {
1403 return 
freaddword($f);
1404 };
1405
1406 function 
freaddword($f)
1407 {
1408  
$b1=freadword($f);
1409  
$b2=freadword($f);
1410  return 
$b2*65536+$b1;
1411 };
1412
1413
1414
1415 function 
RetBits($byte,$start,$len)
1416 {
1417
$bin=decbin8($byte);
1418
$r=bindec(substr($bin,$start,$len));
1419 return 
$r;
1420
1421 };
1422
1423
1424
1425
$CurrentBit=0;
1426 function 
freadbits($f,$count)
1427 {
1428  global 
$CurrentBit,$SMode;
1429  
$Byte=freadbyte($f);
1430  
$LastCBit=$CurrentBit;
1431  
$CurrentBit+=$count;
1432  if(
$CurrentBit==8)
1433   {
1434    
$CurrentBit=0;
1435   }
1436  else
1437   {
1438    
fseek($f,ftell($f)-1);
1439   };
1440  return 
RetBits($Byte,$LastCBit,$count);
1441 };
1442
1443
1444
1445 function 
RGBToHex($Red,$Green,$Blue)
1446   {
1447    
$hRed=dechex($Red);if(strlen($hRed)==1$hRed="0$hRed";
1448    
$hGreen=dechex($Green);if(strlen($hGreen)==1$hGreen="0$hGreen";
1449    
$hBlue=dechex($Blue);if(strlen($hBlue)==1$hBlue="0$hBlue";
1450    return(
$hRed.$hGreen.$hBlue);
1451   };
1452
1453         function 
int_to_dword($n)
1454         {
1455                 return 
chr($n 255).chr(($n >> 8) & 255).chr(($n >> 16) & 255).chr(($n >> 24) & 255);
1456         }
1457         function 
int_to_word($n)
1458         {
1459                 return 
chr($n 255).chr(($n >> 8) & 255);
1460         }
1461
1462
1463 function 
decbin8($d)
1464 {
1465 return 
decbinx($d,8);
1466 };
1467
1468 function 
decbinx($d,$n)
1469 {
1470
$bin=decbin($d);
1471
$sbin=strlen($bin);
1472 for(
$j=0;$j<$n-$sbin;$j++)
1473  
$bin="0$bin";
1474 return 
$bin;
1475 };
1476
1477 function 
inttobyte($n)
1478 {
1479 return 
chr($n);
1480 };
1481
1482 function 
HTMLEncode($text) {
1483 return 
preg_replace(array("/(([\w\.]+))(@)([\w\.]+)\b/i",
1484                           
"/((ftp(7?):\/\/)|(ftp\.))([\w\.\/\&\=\?\-\~]+)/",
1485                           
"/((http(s?):\/\/)|(www\.))([\w\.\/\&\=\?\-\~]+)/"),
1486                     array(
"<a href=\"mailto:{t_source}\">{t_source}</a>",
1487                               
"<a href=\"ftp://\" target=\"_blank\"></a>",
1488                             
"<a href=\"http://\" target=\"_blank\"></a>"), $text);
1489 }
1490
1491 function 
bezier($step,$x0,$y0,$x1,$y1,$x2,$y2,$x3,$y3)
1492 {
1493
1494     
$cx * ($x1 $x0);
1495     
$bx * ($x2 $x1) - $cx;
1496     
$ax $x3 $x0 $cx $bx;
1497     
1498     
$cy * ($y1 $y0);
1499     
$by * ($y2 $y1) - $cy;
1500     
$ay $y3 $y0 $cy $by;
1501
1502     
$t_inc $step;
1503     
1504     for (
$t 0$t <= 1$t += $t_inc)
1505     {
1506         
$ret[X][] = ( $ax pow($t,3) ) + ( $bx pow($t,2) ) + ($cx $t) + $x0;
1507         
$ret[Y][] = ( $ay pow($t,3) ) + ( $by pow($t,2) ) + ($cy $t) + $y0;
1508     }
1509     return 
$ret;
1510 }
1511
1512 function 
draw_puzzle(&$im$l$x0$ly$y0$tc$tc1$o "low"$v "oriz")
1513 {
1514     if (
$o == "low")
1515     {
1516         
$c = array(.9,1.4,1.6,1.4,.9);
1517         
$c1 = array(1.05,.95,1.1,.9);
1518     }
1519     else
1520     {
1521         
$c = array(1.1,.6,.4,.6,1.1);
1522         
$c1 = array(.95,1.05,.9,1.1);
1523     }
1524     
$xi $x0
1525     
$xf $l/* (.85 rand(-10,10)*.003) + $x0;
1526     
$x1 $xi
1527     
$x2 $xf;
1528     
$yi $ly
1529     
$yf $ly $c[0]; 
1530     
$y1 $yi $c1[0]; 
1531     
$y2 $yf $c1[1];
1532     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1533     
1534     
$xi $xf
1535     
$xf $l/* (.75 rand(-10,10)*.003) + $x0
1536     
$x1 $xi$x2 $xf;
1537     
$yi $yf
1538     
$yf $ly $c[1]; 
1539     
$y1 $yi $c1[2]; $y2 $yf $c1[3];
1540     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1541
1542     
$xi $xf
1543     
$xf $l/$x0
1544     
$x1 $xi
1545     
$x2 $xf;
1546     
$yi $yf
1547     
$yf $ly $c[2]; 
1548     
$y1 $yi $c1[2]; $y2 $yf $c1[0];
1549     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1550     
1551     
$xi $xf
1552     
$xf $l/* (1.25 rand(-10,10)*.003) + $x0
1553     
$x1 $xi$x2 $xf;
1554     
$yi $yf
1555     
$yf $ly $c[3]; 
1556     
$y1 $yi $c1[0]; $y2 $yf $c1[2];
1557     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1558     
1559     
$xi $xf;
1560     
$xf $l/* (1.15 rand(-10,10)*.003) + $x0;
1561     
$x1 $xi$x2 $xf;
1562     
$yi $yf;
1563     
$yf $ly $c[4];
1564     
$y1 $yi $c1[3]; $y2 $yf $c1[2];
1565     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1566
1567     
$xi $xf
1568     
$xf $l $x0
1569     
$x1 $xi$x2 $xf
1570     
$yi $yf
1571     
$yf $ly
1572     
$y1 $yi $c1[1]; $y2 $yf $c1[0]; 
1573     
$test[] = bezier(100$xi,$yi+$y0,$x1,$y1+$y0,$x2,$y2+$y0,$xf,$yf+$y0);
1574
1575
1576     for (
$n 0$n count($test); $n++)
1577     {
1578         if (
$v == "oriz")
1579         {
1580             for (
$i 0$i count($test[$n][X])-1$i++)
1581             {
1582                 
imagelinethick($im$test[$n][X][$i],$test[$n][Y][$i],$test[$n][X][$i+1],$test[$n][Y][$i+1],$tc,3);
1583             }
1584         }
1585         else
1586         {
1587             for (
$i 0$i count($test[$n][X])-1$i++)
1588             {
1589                 
imagelinethick($im$test[$n][Y][$i],$test[$n][X][$i],$test[$n][Y][$i+1],$test[$n][X][$i+1],$tc,3);
1590             }
1591         }
1592     }
1593     for (
$n 0$n count($test); $n++)
1594     {
1595         if (
$v == "oriz")
1596         {
1597             for (
$i 0$i count($test[$n][X])-1$i++)
1598             {
1599                 
imageline($im$test[$n][X][$i],$test[$n][Y][$i],$test[$n][X][$i+1],$test[$n][Y][$i+1],$tc1);
1600             }
1601         }
1602         else
1603         {
1604             for (
$i 0$i count($test[$n][X])-1$i++)
1605             {
1606                 
imageline($im$test[$n][Y][$i],$test[$n][X][$i],$test[$n][Y][$i+1],$test[$n][X][$i+1],$tc1);
1607             }
1608         }
1609     }    
1610 }
1611
1612
1613 function 
imagelinethick($image$x1$y1$x2$y2$color$thick 1
1614 {
1615    
/* this way it works well only for orthogonal lines
1616    imagesetthickness($image, $thick);
1617    return imageline($image, $x1, $y1, $x2, $y2, $color);
1618    */
1619    
if ($thick == 1) {
1620        return 
imageline($image$x1$y1$x2$y2$color);
1621    }
1622    
$t $thick 0.5;
1623    if (
$x1 == $x2 || $y1 == $y2) {
1624        return 
imagefilledrectangle($imageround(min($x1$x2) - $t), round(min($y1$y2) - $t), round(max($x1$x2) + $t), round(max($y1$y2) + $t), $color);
1625    }
1626    
$k = ($y2 $y1) / ($x2 $x1); //y = kx + q
1627    
$a $t sqrt(pow($k2));
1628    
$points = array(
1629        
round($x1 - (1+$k)*$a), round($y1 + (1-$k)*$a),
1630        
round($x1 - (1-$k)*$a), round($y1 - (1+$k)*$a),
1631        
round($x2 + (1+$k)*$a), round($y2 - (1-$k)*$a),
1632        
round($x2 + (1-$k)*$a), round($y2 + (1+$k)*$a),
1633    );    
1634    
imagefilledpolygon($image$points4$color);
1635    return 
imagepolygon($image$points4$color);
1636 }
1637
1638
?>

Hide line numbers

 

 
 

Home  l  Image to Text  l  Image to Ascii  l  Image to Table  l  Image to Puzzle  l  Color Chooser l  Color Wheel l  Source Code

DM Image Artworks v.2.1.0 2005 CereS - Divxmania.it

Italiano English

 

Done in: 0.1113 seconds