$invert = isset($_POST["invert"]) ? true : false;
?>
if (!isset($_FILES["file"]))
die();
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "
";
die();
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "
";
echo "Type: " . $_FILES["file"]["type"] . "
";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB
";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
$name = $_FILES["file"]["tmp_name"];
$im = imagecreatefrompng($name);
$size = getimagesize($name);
$w = $size[0];
$h = $size[1];
$bytes = $w.", ".round(ceil($h/8.0) * 8).", ";
for ($r = 0; $r < ceil($h/8.0); $r++)
{
for ($x=0; $x<$w; $x++)
{
$byte = 0;
for ($i=0;$i<8;$i++)
{
$y = 8*$r + $i;
if ($x >= $w || $y >= $h)
$rgb = 1;
else
$rgb = imagecolorat($im, $x, $y);
if ($invert)
{
if ($rgb == 0)
$byte |= (1 << $i);
}
else
{
if ($rgb != 0)
$byte |= (1 << $i);
}
}
$bytes .= $byte.", ";
}
}
echo "
";
echo $bytes;
echo "
";
?>