<?php
$filename="vast/Vastopolis_Map.png";
$image = imagecreatefrompng($filename);
// get properties of the image as an array $size
// $size[0] is the width of the image in pixel
// $size[1] is the height
$size = getimagesize($filename);
$width = $size[0];
$height = $size[1];
// Set the color (red)
$ink_color = imagecolorallocatealpha ($image, 244, 1, 1, 100);
// Set line thickness if needed
// imagesetthickness($image, 5);
// get GPS locations where text meets selection criteria
// Connect to MySQL, assume the database is called vast
$dsn = 'mysql:host=localhost;dbname=vast';
$username = '###';
$passwd = '###';
$db = new PDO($dsn, $username, $passwd);
// Select text that mentions flu or fever
// Option 1: text like '%flu%' or text like '%fever%'
// Option 2: text regexp 'flu|fever'
$sql = "SELECT Location, Text FROM blogs WHERE Text LIKE '%flu%' '";
$results = $db->query($sql);
// Linear transformation to match the coordinates on the map
// The upper left corner of the map: 42.3017, 93.5673
// The lower right corner of the map: 42.1609, 93.1923
$minX = 42.3017;
$maxX = 42.1609;
$minY = 93.5673;
$maxY = 93.1923;
// Linear transformation. What does it do?
$a = $width/($maxX-$minX);
$b = -$minX*$a;
$c = $height/($maxY-$minY);
$d = -$minY*$c;
// Set the color of the markers - red
$color = imagecolorallocatealpha ($image, 250, 10, 10, 50);
// plot each location returned from the query to the database
foreach ($results as $row) {
$location = $row[0];
$pos = preg_split("/\s+/", $location); // why?
$X = $pos[0];
$Y = $pos[1];
$x = $a*$X + $b;
$y = $c*$Y + $d;
imagefilledellipse($image, $x, $y, 10, 10, $color);
}
// serve the image to the client
header ("Content-type: image/png");
imagepng($image);
imagedestroy($image);
?>
它抛出这个恶心的错误,任何人?Php错误 - 不确定它来自哪里或它的含义?
Warning: Invalid argument supplied for foreach() on line 51
Warning: Cannot modify header information - headers already sent by on line 61
‰PNG IHDR` ]×ý{~÷PLTEôú ûûûèæÙãÒìæÓÔÖçæËäÎÑÐêÒÐÑæï®âæšìÎéšÈê³ØâšËÔ¯ËËä¼åæ·ËзæˬÏÃÆæ®ã¸‘ä æŽÏ®¯Ð‰Ç—¬Æ‘Œºãó»ãÒ·Èí±ÒÆË÷˜Èù䫷⚮̪̑›Â±šÄŠ¨Ï®²®‹®°Œ’´§¬Ž’§‹‹ÄÅyäyæ€}ò‘IÌ¥yõYĘpÃ[ùƒ+Ê8®Â{¬¬m¤¥Z±i®„X‰¬q™¢Y‹“nŽP¨¢;¤‚<‘ >„ˆ;„å}Är¦É}ƒ{ͤ|¤§v¦\¡©VŒ–v¤mX¨…\…‘2‡çppð`^ç\bêPQÔpqÊnVÒ]bÔQRíy%þjë@>ìZÌr'ÒiØA>ÍX ð=CÔ>Bë34ñ!þ"ý Õ67Å:̧rn¥yQ¢\f«RSnm‘mLŠYo†YL£v;´e«\+±XŽf:ƒm†Y5ŒT®=F†2m„:L‚m/1®'¾‰2+‚'Ž ƒ rÀúT¤ázª¤|¢{ˆ¢s“‰P¥¥U¨‰O‡¯[ˆƒ“þ-ƒ¸-‘¶……z£ix¡[qllŽT[¡n_ C[ƒrZ…Lxƒ:iƒU…:Sƒ2‡m4„W‚w…N2ƒg`Õsk³qsˆdZ´tU†Jx©[iƒUK±UMŽC;Ùj0‡d‡E9¬H8\ {È&mŸ$á3)®3'—&®&”‘mmpltPmRnqQNVpmToLSUkOONqn6~jrO0kHNm5Z}NT0NNfde:.f:p#~R4/N0L-C8kf-lG8Kf4PN~~lDJ~GH*g7&~2R-/Md8sU-G63c25M#}5Jtéã°ER¶ÁSÆ3tŸwC×ëx<ñ“ÏɼøÇvæßžpvü0#V>¶[û]oGÿÏÓc{ÚhEõlóï‡1g çFû|‡Úà®–\¿^o×ö~mÏãO?ÿô`Åè^<ë®òe{öØÓ>°ý~ק íøszŠè꾪nz¤>â<äø°^÷:̶óu;ö]…:þtÜöUÍ’«6QvKn|@ÉÖL¸ëoêk8|`ítSû9«°\Ú³Ï'BÆ•¥5ڪ㎨_tû «¬tøíúív½¶;ÿÝow>»À›íÃÃÑÊÓuµýò𪪶Gœ€Õvª?”è”;Ee§`þm{az`ŸåzÄyí1"‹žÝÑÎ÷ÓqTÓXÕvÖKí÷
不知道这是一个数据库错误,或用PHP的东西。完全失去了为什么要这样做,或者它在谈论什么。
+1用于捕获额外的':-) – Homer6 2011-04-27 00:39:15
良好的工作shmeeps,这个固定! – Jshee 2011-04-27 00:43:03
@ user700070没问题,很高兴我可以帮忙! – shmeeps 2011-04-27 00:47:57