非结构化、无清理或错误检查示例:
<?php
$plik = <<<EOD
204 13 225 59
225 59 226 84
226 84 219 111
219 111 244 192
244 192 236 209
236 209 254 223
254 223 276 258
276 258 237 337
EOD;
$plik = preg_replace('/\r\n?/', "\n", $plik);
$arr = explode("\n", $plik);
array_walk($arr,
function (&$value, $key) {
$value = explode(' ', $value);
}
);
$minwidth = array_reduce($arr,
function ($res, $val) { return min($res, $val[0], $val[2]); },
PHP_INT_MAX);
$maxwidth = array_reduce($arr,
function ($res, $val) { return max($res, $val[0], $val[2]); },
(PHP_INT_MAX * -1) - 1);
$minheight = array_reduce($arr,
function ($res, $val) { return min($res, $val[1], $val[3]); },
PHP_INT_MAX);
$maxheight = array_reduce($arr,
function ($res, $val) { return max($res, $val[1], $val[3]); },
(PHP_INT_MAX * -1) - 1);
/* note: The image does not reflect the "+ 1"'s I added in a subsequent edit */
$mapa = imagecreatetruecolor($maxwidth - $minwidth + 1, $maxheight - $minheight + 1);
$kolor = imagecolorallocate($mapa, 100, 200, 50);
foreach ($arr as $k) {
imageline($mapa,
$k[0] - $minwidth,
$k[1] - $minheight,
$k[2] - $minwidth,
$k[3] - $minheight, $kolor );
}
header("Content-type: image/png");
imagepng($mapa);
结果: