<?php
/*
 * Code-Wallpaper
 * written by Raphael Michel
 * public domain
 * 
 * Auszuführen auf CLI
 * content.txt enthält den Code in Hintergrund, im Beispiel jQuery+jQueryUI.
 * Alles was in der Input-Datei (PNG) _weiß_ ist, ist nachher hervorgehoben.
 */
$f fopen("php://stdin""r");
echo 
"Input-Datei: ";
$file trim(fgets($f));
echo 
"\n";
$src imagecreatefrompng($file);
$im imagecreatetruecolor(imagesx($src),imagesy($src));
echo 
"Lese content.txt aus...\n";
$string file_get_contents('content.txt');
$arr str_split($string500);
echo 
"Generiere Hintergrund...\n";
foreach(
$arr as $n => $str){
    
imagestring($im00, ($n*10), $strimagecolorallocate($im0500));
}

echo 
"Färbe Pixel...  ";
$max imagesx($src)*imagesy($src);
$max str_pad($max7'0'STR_PAD_LEFT);
echo 
"0000000/".$max;
$i 0;
for(
$x 0$x imagesx($src); $x++){
    for(
$y 0$y imagesy($src); $y++){
        
$i++;
        if(
$i%100 == 0){
            echo 
str_repeat(chr(8), 15);
            echo 
str_pad($i7'0'STR_PAD_LEFT)."/".$max;
        }
        
$at imagecolorat($im$x$y);
        
$dec goback($at);
        if(
$dec == array(0,50,0)){
            
$srcat imagecolorat($src$x$y);
            
$srcdec goback($srcat);
            if(
$srcdec == array(255,255,255)){
                
imagesetpixel($im$x$yimagecolorallocate($im01500));
            }
        }
    }
}


echo 
"\nSpeichere...\n";
imagepng($im'wallpaper_'.$file);
imagedestroy($im);
imagedestroy($src);
echo 
"\nFertig!\n";
system('wallpaper_'.$file);

function 
goback($col) {
    
$new dechex($col);
    
$new str_repeat('0'6-strlen($new)).$new;
    return array(
        
hexdec(substr($new02)),
        
hexdec(substr($new22)),
        
hexdec(substr($new42)));
}