{"id":24329,"date":"2024-11-21T10:09:10","date_gmt":"2024-11-21T02:09:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/24329\/"},"modified":"2024-11-21T10:09:10","modified_gmt":"2024-11-21T02:09:10","slug":"thinkphp6%e5%9b%be%e7%89%87%e5%a4%84%e7%90%86%e4%b8%8e%e8%a3%81%e5%89%aa%ef%bc%9a%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e7%9a%84%e7%bc%96%e8%be%91%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/24329\/","title":{"rendered":"ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169183878751963.jpg\" class=\"aligncenter\" title=\"ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u63d2\u56fe\" alt=\"ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u63d2\u56fe\" \/><\/p>\n<p>ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd<\/p>\n<p>\u5728\u73b0\u4ee3Web\u5f00\u53d1\u4e2d\uff0c\u56fe\u7247\u5904\u7406\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u5fc5\u4e0d\u53ef\u5c11\u7684\u9700\u6c42\u3002\u800c\u5229\u7528ThinkPHP6\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\u7684\u529f\u80fd\u3002\u672c\u6587\u5c06\u5e26\u60a8\u4e86\u89e3\u5982\u4f55\u5229\u7528ThinkPHP6\u7684\u56fe\u7247\u5904\u7406\u5e93\u6765\u7f16\u8f91\u56fe\u7247\u3002<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728composer.json\u6587\u4ef6\u4e2d\u5f15\u5165\u56fe\u7247\u5904\u7406\u5e93\uff1a<\/p>\n<pre>\"require\": {\n    \"topthink\/think-image\": \"2.*\"\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\uff0c\u6267\u884ccomposer update\u547d\u4ee4\u6765\u5b89\u88c5\u56fe\u7247\u5904\u7406\u5e93\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u56fe\u7247\u5904\u7406\u7684\u63a7\u5236\u5668\u548c\u89c6\u56fe\u6587\u4ef6\u3002<\/p>\n<p>\u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aImageController.php\u7684\u63a7\u5236\u5668\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>&lt;?php declare(strict_types=1);\n\nnamespace appcontroller;\n\nuse thinkController;\nuse thinkImage;\n\nclass ImageController extends Controller\n{\n    public function index()\n    {\n        \/\/ \u56fe\u7247\u8def\u5f84\n        $path = '.\/public\/image\/example.jpg';\n        \n        \/\/ \u6253\u5f00\u56fe\u7247\u5e76\u8fdb\u884c\u88c1\u526a\n        $image = Image::open($path);\n        $image-&gt;crop(200, 200)-&amp;gt;save('.\/public\/image\/example2.jpg');\n        \n        \/\/ \u6e32\u67d3\u89c6\u56fe\n        return view('image\/index', [\n            'image' =&amp;gt; $image,\n        ]);\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u63a7\u5236\u5668\u4e2d\u7684index\u65b9\u6cd5\u6253\u5f00\u4e86\u4e00\u4e2a\u540d\u4e3aexample.jpg\u7684\u56fe\u7247\uff0c\u5e76\u5bf9\u5176\u8fdb\u884c\u4e86200&#215;200\u50cf\u7d20\u7684\u88c1\u526a\uff0c\u5e76\u5c06\u88c1\u526a\u540e\u7684\u56fe\u7247\u4fdd\u5b58\u4e3aexample2.jpg\u3002\u63a5\u7740\uff0c\u6211\u4eec\u5c06\u6e32\u67d3\u4e00\u4e2a\u540d\u4e3aimage\/index.html\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u5c06\u88c1\u526a\u540e\u7684\u56fe\u7247\u663e\u793a\u5728\u9875\u9762\u4e0a\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aindex.html\u7684\u89c6\u56fe\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>\n\n\n    &lt;meta charset=\"utf-8\"&gt;&lt;title&gt;\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a&lt;\/title&gt;&lt;h1&gt;\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a&lt;\/h1&gt;\n    \n    @@##@@\n\n<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u89c6\u56fe\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86<img decoding=\"async\" src=\"https:\/\/www.php.cn\/image\/example2.jpg\" class=\"aligncenter\" title=\"ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u63d2\u56fe1\" alt=\"ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u63d2\u56fe1\" \/>\u6807\u7b7e\u6765\u663e\u793a\u88c1\u526a\u540e\u7684\u56fe\u7247\u3002<\/p>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5728\u8def\u7531\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u76f8\u5e94\u7684\u8def\u7531\u89c4\u5219\u3002<\/p>\n<p>\u5728route\/route.php\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>Route::get('\/image', 'ImageController@index');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6837\uff0c\u5f53\u6211\u4eec\u8bbf\u95ee\/image\u65f6\uff0c\u5c31\u4f1a\u6267\u884cImageController\u63a7\u5236\u5668\u4e2d\u7684index\u65b9\u6cd5\u3002<\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u8bbf\u95ee\/image\u6765\u67e5\u770b\u7ed3\u679c\u3002\u5f53\u6211\u4eec\u8bbf\u95ee\/image\u65f6\uff0c\u5c06\u4f1a\u663e\u793a\u88c1\u526a\u540e\u7684\u56fe\u7247\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5229\u7528ThinkPHP6\u56fe\u7247\u5904\u7406\u5e93\u6765\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5bf9\u56fe\u7247\u8fdb\u884c\u88c1\u526a\u3001\u7f29\u653e\u3001\u65cb\u8f6c\u548c\u6c34\u5370\u7b49\u5904\u7406\u64cd\u4f5c\u3002\u5e0c\u671b\u672c\u6587\u80fd\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p><img> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>ThinkPHP6\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\uff1a\u5b9e\u73b0\u56fe\u7247\u7684\u7f16\u8f91\u529f\u80fd \u5728\u73b0\u4ee3Web\u5f00\u53d1\u4e2d\uff0c\u56fe\u7247\u5904\u7406\u662f\u4e00\u4e2a\u5e38\u89c1\u4e14\u5fc5\u4e0d\u53ef\u5c11\u7684\u9700\u6c42\u3002\u800c\u5229\u7528ThinkPHP6\u6846\u67b6\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u5b9e\u73b0\u56fe\u7247\u5904\u7406\u4e0e\u88c1\u526a\u7684\u529f\u80fd\u3002\u672c\u6587\u5c06\u5e26\u60a8\u4e86\u89e3\u5982\u4f55\u5229\u7528ThinkPHP6\u7684\u56fe\u7247\u5904\u7406\u5e93\u6765\u7f16\u8f91\u56fe\u7247\u3002 \u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5728composer.json\u6587\u4ef6\u4e2d\u5f15\u5165\u56fe\u7247\u5904\u7406\u5e93\uff1a &#8220;require&#8221;: { &#8220;topthink\/think-image&#8221;: &#8220;2.*&#8221; } \u767b\u5f55\u540e\u590d\u5236 \u7136\u540e\uff0c\u6267\u884ccomposer update\u547d\u4ee4\u6765\u5b89\u88c5\u56fe\u7247\u5904\u7406\u5e93\u3002 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u56fe\u7247\u5904\u7406\u7684\u63a7\u5236\u5668\u548c\u89c6\u56fe\u6587\u4ef6\u3002 \u9996\u5148\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aImageController.php\u7684\u63a7\u5236\u5668\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a &lt;?php declare(strict_types=1); namespace appcontroller; use thinkController; use thinkImage; class ImageController extends Controller { public function index() { \/\/ \u56fe\u7247\u8def\u5f84 $path = &#8216;.\/public\/image\/example.jpg&#8217;; \/\/ \u6253\u5f00\u56fe\u7247\u5e76\u8fdb\u884c\u88c1\u526a $image = Image::open($path); $image-&gt;crop(200, 200)-&amp;gt;save(&#8216;.\/public\/image\/example2.jpg&#8217;); \/\/ \u6e32\u67d3\u89c6\u56fe return view(&#8216;image\/index&#8217;, [ &#8216;image&#8217; =&amp;gt; $image, ]); } } \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-24329","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24329","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=24329"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/24329\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=24329"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=24329"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=24329"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}