Converted data:




PHP source of this file:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Image2Hex</title>
</head>

<body>


<form action="http://www.koolstof.be/projecten/img2hex/index.php" method="post" enctype="multipart/form-data">

<label>Image to convert (BMP/PNG/JPEG/PNG):</label><br />
<input type="file" name="img"  /><br />
<br />
<input type="submit" value="Send" />

</form>

<br />
Converted data:
<hr />

<pre>
<?php


// Scale 8 bit to 2 bit image colors
function pixrescale($in)
{
    
// 0 -> 0-63
    // 1 -> 64-127
    // 2 -> 128-191
    // 3 -> 192-254

    
if ($in >= 192) return 3;
    if (
$in >= 128) return 2;
    if (
$in >= 64) return 1;
    return 
0;
}

if (isset(
$_FILES['img']))
{

    
// Get image info
    
$imginfo getimagesize($_FILES['img']['tmp_name']);

    
$im NULL;
    switch(
$imginfo['mime'])
    {
        case 
"image/gif":
            
$im imagecreatefromgif($_FILES['img']['tmp_name']);
            break;
            
        case 
"image/bmp":
            
$im imagecreatefromwbmp($_FILES['img']['tmp_name']);
            break;
        
        case 
"image/png":
            
$im imagecreatefrompng($_FILES['img']['tmp_name']);
            break;
            
        case 
"image/jpeg":
            
$im imagecreatefromjpeg($_FILES['img']['tmp_name']);
            break;
            
        default:
            
print_r($imginfo);
            die(
"Unkown file type uploaded!");
            break;
    }
    
    
// Make truetype image
    
$imrgb imagecreatetruecolor($imginfo[0],$imginfo[1]);
    
imagecopyresampled ($imrgb $im 0,0,0,0,$imginfo[0],$imginfo[1],$imginfo[0],$imginfo[1]);
    
    echo 
"byte[] ConvertedImage = new byte[] {  // {$imginfo[0]} x {$imginfo[1]}\n";
    
    for (
$x 0$x $imginfo[1]; $x++)
    {
        for (
$y 0$y $imginfo[0]; $y++)
        {
            
$rgb imagecolorat($imrgb,$y$x);
            
$r pixrescale((($rgb >> 16) & 0xFF)*1);
            
$g pixrescale((($rgb >> 8) & 0xFF)*1);
            
$b pixrescale(($rgb 0xFF)*1);
            
            
$hex = (($r << 4) | ($g << 2) | $b);
            
printf(" 0x%02x",$hex);
            
            if ((
$x != ($imginfo[1] -1)) || ($y != ($imginfo[0] -1)))
            {
                echo 
",";            
            }
        }
        
        echo 
"\n";
    }

    echo 
"};\n";
    
}

?>
</pre>

<br />
<br />
PHP source of this file:
<hr />
<?php
echo highlight_file('index.php',true);
?>
</body>
</html>