Skip to content

Instantly share code, notes, and snippets.

@mgng
Created December 11, 2008 03:26
Show Gist options
  • Save mgng/34594 to your computer and use it in GitHub Desktop.
Save mgng/34594 to your computer and use it in GitHub Desktop.
JPEG 2 ASCII
<?php
// JPEG 2 ASCII
$in = 'test.jpg';
$out = 'test.html';
$buf = '';
$gd = imagecreatefromjpeg($in);
$w = imagesx($gd);
$h = imagesy($gd);
for($y=0; $y<$h; $y++){
for($x=0; $x<$w; $x++){
$rgb = imagecolorat($gd, $x, $y);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$buf .= "<span style=\"color:rgb({$r},{$g},{$b});\">#</span>";
if($w === $x+1){
$buf .= '<br>';
}
}
}
echo "<div style=\"line-height:1px;font-size:1px;\">{$buf}</div>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment