eXorithm – Execute Algorithm: View / Run Algorithm ascii_art

Logo Beta

function ascii_art ($img

{

  $width = imagesx$img);

  $height = imagesy$img);

  

  $ascii = '<pre style="font-size:8px;line-height:1px;letter-spacing:-2px;">'

  

  for$y=0;$y$height$y++)

  {

    for$x=0;$x$width$x++)

    {

      $c = imagecolorat$img$x$y);

      $r = ($c >> 16) & 0xFF;

      $g = ($c >> 8) & 0xFF;

      $b = $c & 0xFF;

      $t = ($c >> 24) & 0xFF;

      if ($t>=0)

      {

        /** transparency **/

        $r = $r+(255-$r)*$t/127;

        $g = $g+(255-$g)*$t/127;

        $b = $b+(255-$b)*$t/127;

      }

      $r = floor$r/16);

      $g = floor$g/16);

      $b = floor$b/16);

      $ascii .= '<span style="color:#'dechex$r).dechex$g).dechex$b).'">#</span>'

    }

    $ascii .= '<br>'

  }

  

  $ascii .= '</pre>'

  

  return $ascii