0) { $nw[] = $currentEqualityValue; } $out = $nw; $sb = "const unsigned int dogee[] = {\r\n"; $cnt = count($out)-1; $lastBreakLen = 0; foreach($out as $i=>$o) { $lb = $i % 10 == 9; $sb.="0x".dechex($o); if($cnt != $i) { $sb.=", "; } $len = strlen($sb); if($len - $lastBreakLen > 150) { $sb.="\r\n"; $lastBreakLen = $len; } } $sb .= "\r\n};\r\n"; return array($sb, $out, $outer); } function decode($img, $out, $outer) { $width = $out[0]; $height = $out[1]; $white = imagecolorallocate($img, 255,255,255); $black = imagecolorallocate($img, 0,0,0); $undef= imagecolorallocate($img, 255,127,127); for($y = 0; $y < $height; $y++) { for($x = 0; $x < $width; $x++) { imagesetpixel($img, $x, $y, $undef); } } $buffer = $out; $currentValIndex = 2; $currentValOffset = 31; $uncodedLeft = 0; $codedLeft = 0; for($y = 0; $y < $height; $y++) { for($x = 0; $x < $width; $x++) { if($uncodedLeft == 0 && $codedLeft == 0) { $uncodedLeft = $out[$currentValIndex] >> 16; $codedLeft = $out[$currentValIndex] & 0xffff; $currentValIndex += 1; } $val = $out[$currentValIndex]; $val = $val >> $currentValOffset; $val = $val & 1; if($currentValOffset == 0) { if($uncodedLeft > 0) { $currentValIndex++; $uncodedLeft--; } else if($codedLeft > 0) { $codedLeft--; if($codedLeft == 0) { $currentValIndex++; } } $currentValOffset = 31; } else { $currentValOffset--; } imagesetpixel($img, $x, $y, $val == 1 ? $black : $white); } } return $img; } function show($img) { header('Content-Type: image/png'); imagepng($img); imagedestroy($img); } if(isset($_GET["scale"])) { $img = getScaled($img, $_GET["scale"]); } list($sb, $out, $outer) = encode($img); if(isset($_GET["output"])) { $output = $_GET["output"]; if($output == "code") { die($sb); } else if($output == "image") { show($img); } else if($output == "test") { $img = decode($img, $out, $outer); show($img); } else { die("Invalid output. Valid is \"code\", \"test\" and \"image\""); } } die("Continue here"); ?>