[php+ice] Working getTexture example

Boris Bogar
2009-07-20
2012-10-30
  • Boris Bogar
    Boris Bogar
    2009-07-20

    Sorry if lack of comments but is a start :)

    <?
    ini_set('memory_limit', '20M');
    $serverID = 1;
    $playerID = 1;

    Ice_loadProfile();

    try {
    $base = $ICE->stringToProxy("Meta:tcp -h 127.0.0.1 -p 6502");
    $meta = $base->ice_checkedCast("::Murmur::Meta");

    $rawTexture = $meta-&gt;getServer($serverID)-&gt;getTexture($playerID);
    
    $bgra = &quot;&quot;;
    foreach($rawTexture AS $val){
        $bgra .= pack('C*', $val);
    }
    $bgra = unpack('C*', gzuncompress($bgra));
    
    $img = imagecreatetruecolor(600,60);
    imagealphablending($img, false);
    imagesavealpha($img, true);
    imagefilledrectangle($img, 0, 0,600, 60,  imagecolorallocatealpha($img, 0, 0, 0,127));
    
    $index = 1;
    for($y=0; $y&lt;60; $y++ ){
        for($x=0; $x&lt; 600; $x++ ){
            imagesetpixel($img, $x, $y, imagecolorallocatealpha($img, $bgra[$index+2], $bgra[$index+1], $bgra[$index], abs(($bgra[$index+3] / 2)-127)));
            $index += 4;
        }
    }
    
    header('Content-type: image/png');
    imagepng($img);
    imagedestroy($img);
    

    } catch (Ice_LocalException $ex) {
    print_r($ex);
    }

    ?>