Table ; type = 2 -> ASCII $breite = $_POST['breite']; $hoehe = $_POST['hoehe']; $bgcolor = $_POST['bgcolor']; $schriftfarbe = $_POST['schriftfarbe']; $lignheight = $_POST['lignheight']; $letterspacing = $_POST['letterspacing']; $fh = $_POST['fh']; // Flip Horizontally $fv = $_POST['fv']; // Flip Vertikally $fehler=""; $inverter=0; $lastspan="c"; if ($fontsize>=13) $size= "c".$fontsize; else $size = "c20"; // was c$fontsize before, but the c20 database just rendered better results. $countascii = strlen($ascii); $asciicounter = 0; // predefined modes if (isset($_GET['mode'])) { $mode = $_GET['mode']; if ($mode == "dot") { $ascii = "."; $color = 1; $fontsize = 13; $type = 2; $lignheight = -11; $letterspacing = -6; $fehler .= "Warning: The rendering in this mode could take a few minutes (be sure to set max_execution_time in php.ini), because every 4th pixel is rendered."; } if ($mode == "bw") { $ascii = "."; $color = 0; $fontsize = 13; $type = 2; $lignheight = -12; $letterspacing = -7; $fehler .= "Warning: The rendering in this mode could take a few minutes (be sure to set max_execution_time in php.ini), because every pixel is rendered."; } if ($mode == "block") { $ascii = ""; $color = 1; $fontsize = 13; $type = 2; $lignheight = -4; $letterspacing = -5; } if ($mode == "square") { $ascii = ""; $color = 1; $fontsize = 13; $type = 2; $lignheight = -10; $letterspacing = -5; $fehler .= "Warning: The rendering in this mode could take a few minutes (be sure to set max_execution_time in php.ini), because every 9th pixel is rendered."; } if ($mode == "matrix") { $fontsize = 13; $type = 2; $inverseascii = 1; $bgcolor = "000000"; $schriftfarbe = "00ff00"; } if ($mode == "matrixsmall") { $fontsize = 6; $type = 2; $lignheight = -3; $letterspacing = -1; $inverseascii = 1; $bgcolor = "000000"; $schriftfarbe = "00ff00"; $fehler .= "Warning: The rendering in this mode could take a few minutes (be sure to set max_execution_time in php.ini), because every 4th pixel is rendered."; } if ($mode == "scratchy") { $color = 1; $fontsize = 13; $type = 2; $inverseascii = 0; $lignheight = -10; $letterspacing = -5; } } if ($type==2) { if ($fontsize==4) { $px = 2+$letterspacing; $py = 4+$lignheight; // when printed $px should be 2.5+$letterspacing, otherwise it should be 2 (for the screen) } if ($fontsize==6) { $px = 4+$letterspacing; $py = 7+$lignheight; } if ($fontsize==8) { $px = 5+$letterspacing; $py = 8+$lignheight; } if ($fontsize==13) { $px = 8+$letterspacing; $py = 13+$lignheight; $vert = $m_t + 3; $horz = $m_l + 7; $vert2 = $m_t + 6; $horz2 = $m_l; } if ($fontsize==16) { $px = 9+$letterspacing; $py = 16+$lignheight; $vert = $m_t + 3; $horz = $m_l + 8; $vert2 = $m_t + 6; $horz2 = $m_l; } if ($fontsize==20) { $px = 12+$letterspacing; $py = 20+$lignheight; $vert = $m_t + 5; $horz = $m_l + 10; $vert2 = $m_t + 10; $horz2 = $m_l; } if ($px <= 0) // to prevent an infinite loop $px = 1; if ($py <= 0) $py = 1; } if ($ascii) // $ascii -> $asciichars[] { $g=0; for ($i=0;$i $max) $max = $pts[0]; $g++; } // end foreach } // endif $ascii } ?> IMG2ASCII - © Ueli Weiss "; if ($breite<1) $fehler.="The height has to be at least 1.
"; } $result = mysql_query("SELECT id,image FROM images"); $datei = mysql_fetch_row($result); // suppr($datei[1]); // deletes the last file used. from the main folder mysql_query("DELETE FROM images WHERE id='$datei[0]'"); mysql_query("INSERT images (image) VALUES ('$file')"); if (is_uploaded_file($_FILES['userfile']['tmp_name']) && $file) // upload img { copy($_FILES['userfile']['tmp_name'],$file); // $file = $_FILES['userfile']['tmp_name']; } elseif (!isset($_GET['mode'])) $fehler.="The file could not be uploaded!
"; if (!eregi("jpeg|gif|png",$_FILES['userfile']['type']) && $file) $fehler.="The file is not a supported image file! (jpg/gif/png)
"; if (!$file && !isset($_GET['mode'])) $fehler.="No image was added!
"; if (count($art)<1 && !isset($_GET['mode']) && $chars=="" && $type==2) $fehler.="Enter at least one type of letters.
"; if (!$fehler && !isset($_GET['mode'])) { $vert = $m_t; $horz = $m_l; $vert2 = $m_t; $horz2 = $m_l; if ($type==1){ $px = $breite; $py = $hoehe; } if (eregi("jpeg",$_FILES['userfile']['type'])) $im = imagecreatefromjpeg($file); if (eregi("gif",$_FILES['userfile']['type'])) // Newer PHP versions do not support GIF images anymore ! $im = imagecreatefromgif($file); if (eregi("png",$_FILES['userfile']['type'])) $im = imagecreatefrompng($file); $size_arr = getimagesize($file); $width=$size_arr[0]; $height=$size_arr[1]; $where = ""; if ($type == 2) { if (count($art)>=1) // if character from select list is selected, in addition then the chars below { foreach ($art as $temp) { if ($temp == 6) // inverse characters (bg-fg) $inverter = 1; } foreach ($art as $temp) { if ($inverter && $temp != 6) // inverse characters (bg-fg) $where .= " type='".$temp."' || type='6|".$temp."' ||"; elseif ($temp != 6) $where .= " type='".$temp."' ||"; } } if ($chars) { if (!$inverter) $where .= "("; for ($i=0;$i") $temp = ">"; $where .= " achar='".$temp."' ||"; } if (!$inverter) { $where = substr($where,0,-3); $where .= ") && id<=256 ||"; } } $where = substr($where,0,-3); if ($art[0]==6 && !$chars) // blank letter inversed - only "inversed" was selected as a letter type { $where = "achar=' '"; } $white = mysql_query("SELECT $size FROM ascii WHERE $where ORDER BY $size ASC LIMIT 1"); $white = mysql_fetch_row($white); // minimum $black = mysql_query("SELECT $size FROM ascii WHERE $where ORDER BY $size DESC LIMIT 1"); $black = mysql_fetch_row($black); // maximum } /************************* TABLE, COLOR *****************************************************/ if ($type==1 && $color){ echo ''; for ($cy=0;$cy<$height;$cy+=$py) { echo "\n"; for ($cx=0;$cx<$width;$cx+=$px) { $x = $cx; $y = $cy; if ($fh) // Flip Horizontally $x = $width - $cx-1; if ($fv) // Flip Horizontally $y = $height - $cy-1; if (!$everypx) { $rgb = ImageColorAt($im, $x, $y); $col = imagecolorsforindex($im, $rgb); $rgb = explode("-",sprintf("%02d-%02d-%02d",$col["red"], $col["green"], $col["blue"])); } if ($everypx) // every pixel is rendered. $col & $rgb will be overwritten. { $r=0; $g=0; $b=0; $pixels=0; for ($x=$cx;$x<$cx+$px;$x++) { for ($y=$cy;$y<$cy+$py;$y++) { if ($y<$height && $x<$width) { $rgb = ImageColorAt($im, $x, $y); $col = imagecolorsforindex($im, $rgb); $rgb = explode("-",sprintf("%02d-%02d-%02d",$col["red"], $col["green"], $col["blue"])); $r += $rgb[0]; $g += $rgb[1]; $b += $rgb[2]; $pixels++; } } } $rgb = array($r/$pixels,$g/$pixels,$b/$pixels); $farbe = ($rgb[0]+$rgb[1]+$rgb[2])/3; } if (!$inverse) { $hex = sprintf("%02x%02x%02x",$rgb[0],$rgb[1],$rgb[2]); } else { $hex = sprintf("%02x%02x%02x",255-$rgb[0],255-$rgb[1],255-$rgb[2]); } echo "\n"; } echo ''; } echo '


'; } /************************* TABLE BLACK WHITE ***********************************/ if ($type==1 && !$color){ echo ''; for ($cy=0;$cy<$height;$cy+=$py) { echo "\n"; for ($cx=0;$cx<$width;$cx+=$px) { $x = $cx; $y = $cy; if ($fh) // Flip Horizontally $x = $width - $cx -1; if ($fv) // Flip Horizontally $y = $height - $cy -1; if (!$everypx) { $rgb = ImageColorAt($im, $x, $y); $col = imagecolorsforindex($im, $rgb); $rgb = explode("-",sprintf("%02d-%02d-%02d",$col["red"], $col["green"], $col["blue"])); $farbe = ($rgb[0]+$rgb[1]+$rgb[2])/3; } if ($everypx) // every pixel is rendered. $col & $rgb will be overwritten. { $r=0; $g=0; $b=0; $pixels=0; for ($x=$cx;$x<$cx+$px;$x++) { for ($y=$cy;$y<$cy+$py;$y++) { if ($y<$height && $x<$width) { $rgb = ImageColorAt($im, $x, $y); $col = imagecolorsforindex($im, $rgb); $rgb = explode("-",sprintf("%02d-%02d-%02d",$col["red"], $col["green"], $col["blue"])); $r += $rgb[0]; $g += $rgb[1]; $b += $rgb[2]; $pixels++; } } } $rgb = array($r/$pixels,$g/$pixels,$b/$pixels); $farbe = ($rgb[0]+$rgb[1]+$rgb[2])/3; } if (!$inverse) $hex = sprintf("%02x%02x%02x",$farbe, $farbe, $farbe); else $hex = sprintf("%02x%02x%02x",255-$farbe, 255-$farbe, 255-$farbe); echo "\n"; } echo ''; } echo '


'; } /************************* ASCII *****************************************/ if ($type==2){ $text = ""; $text.= ""; srand((double)microtime() * 10000000); for ($cy=0;$cy<$height;$cy+=$py) { for ($cx=0;$cx<$width;$cx+=$px) { $x = $cx; $y = $cy; if ($fh) // Flip Horizontally $x = $width - $cx-1; if ($fv) // Flip Horizontally $y = $height - $cy-1; $text .= getchar($x,$y,$im); } $text.= "
\n"; } $text.= "
\n\n"; //$text = strtr($text, $mod); echo $text; if ($layer>=2) echo "
".$text."
\n\n"; if ($layer>=3) echo "
".$text."
\n\n"; if ($layer>=4) echo "
".$text."
\n\n"; if ($layer>=5) echo "
".$text."
\n\n"; if ($layer>=6) echo "
".$text."
\n\n"; ?>

"; } // end if fehler } // end show if (isset($_POST['type']) || $fehler || isset($_GET['mode'])) { ?>

JPG 2
".$fehler."";?>
Image File
Color >
Invert Color >
Invert ASCII >
No Dispersion >
Anti-aliasing
(very time-consuming)
>
Characters
(deselect with CTRL +
left mouse button)
Additional characters
to be used
Font Size
Lign Height
0 is normal
">
Letter Spacing
0 is normal
">
Nr. of Layers
Character(s) to use
ie "hello"
Font Color (HEX) ">
Width of table ">
Height of table ">
Anti-aliasing
(very time-consuming)
>
Background Color (HEX) ">
Flip Horizontally >
Flip Vertically >
 
Select Mode

Dot
Block
Square
Scratchy (1:2)
Matrix (1:3)
Matrix Small (1:1)
IMG2ASCII

Output
 


Reload | Predefined Modes | © Ueli Weiss =$val ORDER BY ($size-$val) ASC LIMIT $depth"); // results higher than value $resultu = mysql_query("SELECT id,$size,type,achar FROM ascii WHERE ($where) && $size<=$val ORDER BY ($val-$size) ASC LIMIT $depth"); // results lower than selection $resultm = mysql_query("SELECT id,$size,type,achar FROM ascii WHERE ($where) && $size<=$val ORDER BY abs($val-$size) ASC LIMIT $depth"); // nearest result - case: $nodispersion $array = array(); $dist = array(); // distance from what it should be for ($lauf=1;$lauf<=2;$lauf++) { if ($nodispersion) $result=$resultm; elseif ($lauf==1) $result=$resulto; elseif ($lauf==2) $result=$resultu; $i=-1; while ($row = mysql_fetch_row($result)) { $i++; if ($i==0){ array_push($array,$row[0]); array_push($dist,abs($row[1]-$val)); } elseif ($row[1]==$last){ array_push($array,$row[0]); array_push($dist,abs($row[1]-$val)); } else break; $last = $row[1]; }//endwhile }//endfor }//endif!$ascii if ($color) { if ($inverse) { $hex = sprintf("%02x%02x%02x",255-$rgb[0],255-$rgb[1],255-$rgb[2]); } else { $hex = sprintf("%02x%02x%02x",$rgb[0],$rgb[1],$rgb[2]); } $text.= ""; } $char=""; if ($nodispersion && !$ascii) { $char = $array[0]; $charid = $char; if (!$htmlencoded) // get actual character from database { $result2 = mysql_query("SELECT achar FROM ascii WHERE id='$charid' LIMIT 1"); $row2 = mysql_fetch_row($result2); $char = $row2[0]; } } elseif (!$ascii) // $nodispersion not with constant char { $p_tot=0; $p=0; $rand = rand(0,100000); $lastel = $dist[count($array)-1]; $firstel = $dist[0]; foreach ($array as $p1){ //echo $p1." "; } //echo "
"; foreach ($dist as $p1){ if ($p1 == $lastel) $p1 = $firstel; else $p1 = $lastel; $p_tot+=$p1; // p=probalility; p_tot = total probability sum } //$p_tot = 1; $last=0; for ($i=0;$i=$last && $rand*$p_tot/100000 <= $p && !$char) // random nr between 0 and p_tot { $char = $array[$i]; $charid = $char; if (!$htmlencoded) // get actual character from database { $result = mysql_query("SELECT achar FROM ascii WHERE id='$charid' LIMIT 1"); $row2 = mysql_fetch_row($result); $char = $row2[0]; } } $last = $p; } } $result = mysql_query("SELECT type FROM ascii WHERE id='$charid' LIMIT 1"); $row3 = mysql_fetch_row($result); if ($row3[0] == 6) { if ($lastspan == "c") { $text.=""; $lastspan="i"; } } elseif ($lastspan=="i") { $text.=""; $lastspan = "c"; } if ($ascii) { $rand = rand(0,100000)/100000; // random number between 0 an 1 $g = $asciicounter%count($asciichars); if ($max==0) $max = 0.001; if ($farbe/255*$asciipts[$g]/$max <= $rand || $color) $text .= $asciichars[$g]; else $text .= " "; $asciicounter++; } // endif $ascii elseif ($charid==32 || $charid==287) $text.= " "; elseif ($lastspan=="i") { if ($htmlencoded) $text.= "&#".($char-255).";"; else $text.= $char; } else { if ($htmlencoded) $text.= "&#".$char.";"; else $text.= $char; } if ($color) $text.= "
"; return ($text); } // File deletion function function suppr($file) { $delete = @unlink($file); if (@file_exists($file)) { $filesys = eregi_replace("/","\\",$file); $delete = @system("del $filesys"); if (@file_exists($file)) { $delete = @chmod ($file, 0775); $delete = @unlink($file); $delete = @system("del $filesys");}}} ?>