{"id":100,"date":"2011-11-26T00:54:38","date_gmt":"2011-11-25T16:54:38","guid":{"rendered":"http:\/\/hahacool.com\/?p=100"},"modified":"2016-12-29T22:44:45","modified_gmt":"2016-12-29T14:44:45","slug":"%e8%8b%a5%e7%be%9a%e8%89%b3%e8%88%9e%e7%b3%bb%e5%88%97-%e7%9d%a1%e8%a1%a3","status":"publish","type":"post","link":"https:\/\/hahacool.com\/?p=100","title":{"rendered":"imagecopyresampled()\u51fd\u6570\u7684\u8bf4\u660e"},"content":{"rendered":"<p><span class=\"function\"><strong>imagecopyresampled()<\/strong><\/span>\u00a0\u8fd9\u4e2a\u51fd\u6570\u5c06\u4e00\u5e45\u56fe\u50cf\u4e2d\u7684\u4e00\u5757\u6b63\u65b9\u5f62\u533a\u57df\u62f7\u8d1d\u5230\u53e6\u4e00\u4e2a\u56fe\u50cf\u4e2d\uff0c\u5e73\u6ed1\u5730\u63d2\u5165\u50cf\u7d20\u503c\u3002\u901a\u5e38\u7528\u6765\u505a\u7f29\u7565\u56fe\u7528\u3002<\/p>\n<p>\u4f46\u662fphp.net\u4e0a\u89e3\u91ca\u7684\u4e0d\u662f\u592a\u6e05\u6670\u3002\u8fd9\u91cc\u81ea\u5df1\u518d\u91cd\u65b0\u6574\u7406\u4e0b\uff1a<\/p>\n<p>\u51fd\u6570\u539f\u578b\uff1a<\/p>\n<p><span class=\"type\">bool<\/span> <span class=\"methodname\"><strong>imagecopyresampled<\/strong><\/span> ( <span class=\"methodparam\"><span class=\"type\">resource<\/span> <code class=\"parameter\">$dst_image<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">resource<\/span> <code class=\"parameter\">$src_image<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$dst_x<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$dst_y<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$src_x<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span><code class=\"parameter\">$src_y<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$dst_w<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$dst_h<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$src_w<\/code><\/span> , <span class=\"methodparam\"><span class=\"type\">int<\/span> <code class=\"parameter\">$src_h<\/code><\/span> )<\/p>\n<p>$dst_image\uff1a\u65b0\u5efa\u7684\u56fe\u7247<\/p>\n<p>$src_image\uff1a\u9700\u8981\u8f7d\u5165\u7684\u56fe\u7247<\/p>\n<p>\u8fd9\u4e24\u4e2a\u6ca1\u4ec0\u4e48\u8bf4\u7684<\/p>\n<p>$dst_x\uff1a\u8bbe\u5b9a\u9700\u8981\u8f7d\u5165\u7684\u56fe\u7247\u5728\u65b0\u56fe\u4e2d\u7684x\u5750\u6807\uff08\u81ea\u5df1\u6309\u9700\u8bbe\u7f6e\uff09<\/p>\n<p>$dst_y\uff1a\u8bbe\u5b9a\u9700\u8981\u8f7d\u5165\u7684\u56fe\u7247\u5728\u65b0\u56fe\u4e2d\u7684y\u5750\u6807\uff08\u81ea\u5df1\u6309\u9700\u8bbe\u7f6e\uff09<\/p>\n<p>\u4ee5\u4e0a\u662f\u6307\u6e90\u56fe\u50cf\u5728\u76ee\u6807\u56fe\u50cf\u91cc\u9762\u7684\u5de6\u4e0a\u89d2\u7684\u5750\u6807\u503c\uff0c\u901a\u5e38\u9700\u8981\u6307\u5b9a\u4e0b\u7684\u3002<\/p>\n<p>$src_x\uff1a\u8bbe\u5b9a\u8f7d\u5165\u56fe\u7247\u8981\u8f7d\u5165\u7684\u533a\u57dfx\u5750\u6807\uff08\u901a\u5e380\uff09<\/p>\n<p>$src_y\uff1a\u8bbe\u5b9a\u8f7d\u5165\u56fe\u7247\u8981\u8f7d\u5165\u7684\u533a\u57dfy\u5750\u6807\uff08\u901a\u5e380\uff09<\/p>\n<p>\u4ee5\u4e0a\u8fd9\u4e24\u4e2a\u53c2\u6570\u5176\u5b9e\u5c31\u662f\u662f\u5728\u539f\u56fe\u4e0a\u622a\u56fe\u4e00\u90e8\u5206\uff0c\u7528\u8fd9\u4e2a\u51fd\u6570\u6765\u505a\u8fd9\u4e2a\u6ca1\u592a\u5927\u610f\u4e49\u611f\u89c9\uff0cPS\u88c1\u5207\u4ee5\u4e0b\u8fd8\u66f4\u65b9\u4fbf\u76f4\u89c2\uff0c\u8fd9\u91cc\u901a\u5e38\u76f4\u63a5\u8bbe\u7f6e0,0\u3002\u5c31\u662f\u8bf4$src_image\u7684\u56fe\u50cf\u5168\u8fdb\u53bb\u3002<\/p>\n<p>$dst_w\uff1a\u8bbe\u5b9a\u8f7d\u5165\u7684\u539f\u56fe\u7684\u5bbd\u5ea6\uff08\u5728\u6b64\u8bbe\u7f6e\u7f29\u653e\uff09<\/p>\n<p>$dst_h\uff1a\u8bbe\u5b9a\u8f7d\u5165\u7684\u539f\u56fe\u7684\u9ad8\u5ea6\uff08\u5728\u6b64\u8bbe\u7f6e\u7f29\u653e\uff09<\/p>\n<p>\u4ee5\u4e0a\u4e24\u4e2a\u53c2\u6570\u94c1\u5b9a\u8981\u81ea\u5df1\u8bbe\u7f6e\u4e0b\u7684\uff0c\u5176\u5b9e\u5c31\u662f\u7f29\u653e\u540e\u7684\u503c\u3002<\/p>\n<p>$src_w\uff1a\u539f\u56fe\u8981\u8f7d\u5165\u7684\u5bbd\u5ea6<\/p>\n<p>$src_h\uff1a\u539f\u56fe\u8981\u8f7d\u5165\u7684\u9ad8\u5ea6<\/p>\n<p>\u4ee5\u4e0a\u4e24\u4e2a\u6ca1\u4ec0\u4e48\u8bf4\u7684\uff0c\u53ef\u4ee5\u81ea\u5df1\u7528<\/p>\n<p><span class=\"type\">int<\/span> <span class=\"methodname\"><strong>imagesx<\/strong><\/span> ( <span class=\"methodparam\"><span class=\"type\">resource<\/span> <code class=\"parameter\">$image<\/code><\/span> )\u548c<span class=\"type\">int<\/span> <span class=\"methodname\"><strong>imagesy<\/strong><\/span> ( <span class=\"methodparam\"><span class=\"type\">resource<\/span> <code class=\"parameter\">$image<\/code><\/span> )\u8fd9\u4e24\u4e2a\u51fd\u6570\u53bb\u7b97$src_image\u5f97\u51fa\u5c31\u884c\u3002<\/p>\n<p>\u7efc\u4e0a\uff0c\u6b64\u51fd\u6570\u4e00\u822c\u9700\u8981\u81ea\u5df1\u591a\u8003\u8651\u7684\u5c31\u662f$dst_x,y,w,h\u8fd9\u56db\u4e2a\u53c2\u6570\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u4ee5\u4e0b\u4e3a\u8bd5\u9a8c\u4ee3\u7801\uff0c\u53ef\u4ee5\u81ea\u5df1\u4e0d\u65ad\u53d8\u52a8\u91cc\u9762\u7684\u53c2\u6570\u6765\u4f53\u4f1a<\/p>\n<p>&lt;?php<br \/>\nheader(&#8216;Content-Type: image\/jpeg&#8217;);<\/p>\n<p>$img = ImageCreateTrueColor ( 500, 500 );\/\/\u753b\u5e03\u521d\u59cb\u9ed1\u8272\u7684<br \/>\n$purple = ImageColorAllocate ( $img, 220, 120, 255 ); \/\/\u5b9a\u4e49\u56fe\u50cf\u989c\u8272<br \/>\nimagefilledrectangle ( $img, 0, 0, 250,250, $purple); \/\/ \u586b\u5145\u80cc\u666f\u8272<\/p>\n<p>$im=ImageCreateTrueColor ( 500, 500 );<br \/>\n$green = ImageColorAllocate ( $im, 10, 60, 20 );<br \/>\nimagefilledrectangle ( $im, 0, 0, 250,250, $green);<\/p>\n<p>imagecopyresampled ( $img, $im, 100,100, 0,0, 150, 150, 250,250 );<br \/>\nImageJpeg($img);<\/p>\n<p>imagedestroy ( $img );<br \/>\nimagedestroy ( $im );<br \/>\n?&gt;<\/p>\n<p>\u4ee5\u4e0ahahacool\u7ad9\u957f\u539f\u521b\uff0c\u8f6c\u8f7d\u6ce8\u660e\u51fa\u5904<\/p>\n","protected":false},"excerpt":{"rendered":"<p>imagecopyresampled()\u00a0\u8fd9\u4e2a\u51fd\u6570\u5c06\u4e00\u5e45\u56fe\u50cf\u4e2d\u7684\u4e00\u5757\u6b63\u65b9\u5f62\u533a\u57df\u62f7\u8d1d\u5230\u53e6\u4e00\u4e2a\u56fe\u50cf\u4e2d\uff0c\u5e73\u6ed1\u5730\u63d2\u5165\u50cf [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[166],"tags":[171],"class_list":["post-100","post","type-post","status-publish","format-standard","hentry","category-it","tag-171"],"views":1186,"_links":{"self":[{"href":"https:\/\/hahacool.com\/index.php?rest_route=\/wp\/v2\/posts\/100"}],"collection":[{"href":"https:\/\/hahacool.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hahacool.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hahacool.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hahacool.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=100"}],"version-history":[{"count":0,"href":"https:\/\/hahacool.com\/index.php?rest_route=\/wp\/v2\/posts\/100\/revisions"}],"wp:attachment":[{"href":"https:\/\/hahacool.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hahacool.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hahacool.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}