 {"id":467,"date":"2012-06-04T23:28:44","date_gmt":"2012-06-04T15:28:44","guid":{"rendered":"http:\/\/www.qyuef.com\/?p=467"},"modified":"2012-06-04T23:28:44","modified_gmt":"2012-06-04T15:28:44","slug":"php%e5%a6%82%e4%bd%95%e8%ae%a9%e7%94%9f%e6%88%90gif%e6%a0%bc%e5%bc%8f%e7%9a%84%e5%9b%be%e7%89%87%e9%aa%8c%e8%af%81%e7%a0%81","status":"publish","type":"post","link":"http:\/\/www.qyuef.com\/?p=467","title":{"rendered":"PHP\u5982\u4f55\u8ba9\u751f\u6210GIF\u683c\u5f0f\u7684\u56fe\u7247\u9a8c\u8bc1\u7801"},"content":{"rendered":"<p>\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u60f3\u8fc7\u5982\u4f55\u7528PHP\u751f\u6210GIF\u52a8\u753b\u6765\u5b9e\u73b0\u52a8\u6001\u56fe\u7247\u9a8c\u8bc1\u7801\uff0c\u4ee5\u4e0b\u662f\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n<p>\u3000\u3000ImageCode\u51fd\u6570\u901a\u8fc7GIFEncoder\u7c7b\u5b9e\u73b0\u7684GIF\u52a8\u753b\u7684PHP\u6e90\u4ee3\u7801\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u7814\u7a76\u4e00\u4e0b\u3002<\/p>\n<p><strong>\u3000\u3000\u6548\u679c\u5982\u56fe\uff1a<\/strong><\/p>\n<p><center><\/p>\n<p><img loading=\"lazy\" alt=\"\u70b9\u51fb\u67e5\u770b\u539f\u56fe\" height=\"25\" class=\"lazyload \" src=\"http:\/\/www.qyuef.com\/wp-content\/themes\/2022072007404724\/img\/post_loading.gif\" data-original=\"http:\/\/www.php100.com\/uploadfile\/2012\/0525\/20120525095344462.gif\" width=\"60\" \/><\/p>\n<p style=\"text-align: left\">&nbsp;<\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000\/**<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000* ImageCode \u751f\u6210GIF\u56fe\u7247\u9a8c\u8bc1<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000* @param $string \u5b57\u7b26\u4e32<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000* @param $width \u5bbd\u5ea6<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000* @param $height \u9ad8\u5ea6<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000* *\/<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000function ImageCode($string = &#39;&#39;, $width = 75, $height = 25)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$authstr = $string ? $string : ((time() % 2 == 0) ? mt_rand(1000, 9999) : mt_rand(10000, 99999));<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$board_width = $width;<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$board_height = $height;<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000\/\/ \u751f\u6210\u4e00\u4e2a32\u5e27\u7684GIF\u52a8\u753b<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000for($i = 0; $i &lt; 32; $i++)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000ob_start();<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$image = imagecreate($board_width, $board_height);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagecolorallocate($image, 0,0,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000\/\/ \u8bbe\u5b9a\u6587\u5b57\u989c\u8272\u6570\u7ec4<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 15,73,210);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,64,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,0,64);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,128,128);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 27,52,47);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 51,0,102);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,0,145);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,0,113);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,51,51);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 158,180,35);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 59,59,59);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,0,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 1,128,180);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,153,51);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 60,131,1);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorList[] = ImageColorAllocate($image, 0,0,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$fontcolor = ImageColorAllocate($image, 0,0,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$gray = ImageColorAllocate($image, 245,245,245);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$color = imagecolorallocate($image, 255,255,255);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$color2 = imagecolorallocate($image, 255,0,0);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagefill($image, 0, 0, $gray);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$space = 15; \/\/ \u5b57\u7b26\u95f4\u8ddd<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000if($i &gt; 0) \/\/ \u5c4f\u853d\u7b2c\u4e00\u5e27<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000for ($k = 0; $k &lt; strlen($authstr); $k++)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorRandom = mt_rand(0,sizeof($colorList)-1);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$float_top = rand(0,4);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$float_left = rand(0,3);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagestring($image, 6, $space * $k, $top + $float_top, substr($authstr, $k, 1), $colorList[$colorRandom]);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000for ($k = 0; $k &lt; 20; $k++)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorRandom = mt_rand(0,sizeof($colorList)-1);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagesetpixel($image, rand()%70 , rand()%15 , $colorList[$colorRandom]);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000\/\/ \u6dfb\u52a0\u5e72\u6270\u7ebf<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000for($k = 0; $k &lt; 3; $k++)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$colorRandom = mt_rand(0, sizeof($colorList)-1);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000\/\/ $todrawline = rand(0,1);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$todrawline = 1;<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000if($todrawline)<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imageline($image, mt_rand(0, $board_width), mt_rand(0,$board_height), mt_rand(0,$board_width), mt_rand(0,$board_height), $colorList[$colorRandom]);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000else<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000{<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$w = mt_rand(0,$board_width);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$h = mt_rand(0,$board_width);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagearc($image, $board_width &#8211; floor($w \/ 2) , floor($h \/ 2), $w, $h, rand(90,180), rand(180,270), $colorList[$colorRandom]);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagegif($image);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000imagedestroy($image);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$imagedata[] = ob_get_contents();<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000ob_clean();<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000++$i;<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000$gif = new GIFEncoder($imagedata);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000Header (&#39;Content-type:image\/gif&#39;);<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000echo $gif-&gt;GetAnimation();<\/span><\/p>\n<p><span style=\"color: rgb(0,128,0)\">\u3000\u3000}<\/span><\/p>\n<p><\/center><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76f8\u4fe1\u5f88\u591a\u4eba\u90fd\u60f3\u8fc7\u5982\u4f55\u7528PHP\u751f\u6210GIF\u52a8\u753b\u6765\u5b9e\u73b0\u52a8\u6001\u56fe\u7247\u9a8c\u8bc1\u7801\uff0c\u4ee5\u4e0b\u662f\u5b9e\u73b0\u8fc7\u7a0b\u3002<\/p>\n<p>\u3000\u3000ImageCode\u51fd\u6570\u901a\u8fc7GIFEncoder\u7c7b\u5b9e\u73b0\u7684GIF\u52a8\u753b\u7684PHP\u6e90\u4ee3\u7801\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u7814\u7a76\u4e00\u4e0b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[],"tcat":[],"_links":{"self":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/467"}],"collection":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=467"}],"version-history":[{"count":0,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=\/wp\/v2\/posts\/467\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=467"},{"taxonomy":"tcat","embeddable":true,"href":"http:\/\/www.qyuef.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftcat&post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}