'getterrainheight', 'group' => $GROUP, 'entity' => 'region', 'password' => $PASSWORD ); # We now escape each key and value: this is very important, because the # data we send to Corrade may contain the '&' or '=' characters (we don't # in this example though but this will not hurt anyone). array_walk($params, function(&$value, $key) { $value = rawurlencode($key)."=".rawurlencode($value); } ); $postvars = implode('&', $params); # Set the options, send the request and then display the outcome if (!($curl = curl_init())) { echo "Could not initialise CURL".PHP_EOL; } curl_setopt($curl, CURLOPT_URL, $URL); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $postvars); $return = curl_exec($curl); curl_close($curl); $success = urldecode( wasKeyValueGet( "success", $return ) ); // Unable to get the region heights? if($success == 'False') return -1; $map = str_getcsv( urldecode( wasKeyValueGet( "data", $return ) ) ); $max = max($map); $im = imagecreatetruecolor(256, 256); foreach(range(0, 255) as $x) { foreach(range(0, 255) as $y) { $red = mapValueToRange( $map[256 * $x + $y], 0, $max, 0, 256 ); imagesetpixel( $im, $x, 256-$y, imagecolorallocate( $im, $red, 0, 0 ) ); } } /* Uncomment to return Base64 data. * ob_start(); * imagepng($im); * $png = ob_get_contents(); * imagedestroy($im); * ob_end_clean(); * echo base64_encode($png); */ /* Just display the image. */ header('Content-Type: image/png'); imagepng($im); ?>