{"id":683,"date":"2021-12-01T18:11:32","date_gmt":"2021-12-01T10:11:32","guid":{"rendered":"https:\/\/log.tanxiaodian.com\/?p=683"},"modified":"2021-12-01T18:13:33","modified_gmt":"2021-12-01T10:13:33","slug":"%e5%9b%be%e7%89%87%e8%a3%81%e5%89%aa","status":"publish","type":"post","link":"https:\/\/log.tanxiaodian.com\/?p=683","title":{"rendered":"\u56fe\u7247\u88c1\u526a"},"content":{"rendered":"\n<p>\u4e1a\u52a1\u8bf4\u660e:\u7531\u4e8eios\u6700\u5927\u652f\u63012048 * 2048\u7684\u56fe\u7247   ,\u76ee\u524d\u7cfb\u7edf\u4e2d\u6709\u5f88\u591a\u8d85\u957f\u7684\u56fe\u7247  \u56e0\u6b64\u9700\u8981\u8fdb\u884c\u88c1\u526a\uff0c\u800c\u4e14\u8981\u4fee\u6539\u6570\u636e\u5e93\u4e2d\u4e00\u4e2ajson\u683c\u5f0f\u7684\u5b57\u6bb5\uff0c\u9700\u8981\u5728\u957f\u56fe\u7684\u4f4d\u7f6e\u5220\u9664\u539f\u5bf9\u8c61\u7d27\u63a5\u7740\u63d2\u5165\u5206\u5272\u540e\u7684\u56fe\u7247\u5730\u5740<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\/\/\u56fe\u7247\u5206\u5272 ios \u56fe\u7247\u4e0d\u8981\u8d85\u8fc7 2048\nprivate function excisionImage(Good $good, $storagePath)\n{\n    $imgListJson = json_decode($good-&gt;getAttributes()['image_list'], true);\/\/$image-&gt;image_list;\n    $willToChange = [];\n    foreach ($imgListJson as $key =&gt; $item) {\n        if($imgUrl = $item['url']) {\n            \/\/\u6784\u9020\u8def\u5f84\n            $filePath = str_replace('storage', $storagePath, $imgUrl);\n            \/\/\u83b7\u53d6\u56fe\u7247\u4fe1\u606f\u7528\u4e8e\u5224\u65ad\n            if(file_exists($filePath)) {\n                $arrPath = pathinfo($filePath);\n                $path = $arrPath['dirname'];\n                $fileName = $arrPath['filename'];\n                $extName = $arrPath['extension'];\n                list($width, $height, $type, $attr) = getimagesize($filePath);\n\n                if($height &gt; self::<em>IMAGE_LENGTH<\/em>) {\n                    if($type == <em>IMAGETYPE_JPEG<\/em>) {\n                        $funExt = 'jpeg';\/\/imagecreatefromjpeg($filePath)\n                    } elseif($type == <em>IMAGETYPE_PNG<\/em>) {\n                        $funExt = 'png';\n                    } elseif($type == <em>IMAGETYPE_GIF<\/em>) {\n                        $funExt = 'gif';\n                    }\n                    $funCreate = \"imagecreatefrom{$funExt}\";\n                    $img = $funCreate($filePath);\n                    $maxW = $width;\n                    $maxH = self::<em>IMAGE_LENGTH<\/em>;\n                    $funImg = \"image{$funExt}\";\n                    $arrImgFg = [];\n                    for ($i = 0; $i &lt; ceil($height \/ $maxH); $i++) {\n                        $newfile = \"{$path}\/{$fileName}_{$i}.\" . $extName;\n                        if ($i == (ceil($height \/ $maxH) - 1)) {\n                            $maxHx = $height - $maxH * $i;\n                            $iOut = @imagecreatetruecolor($maxW, $maxHx);\n                        } else {\n                            $iOut = @imagecreatetruecolor($maxW, $maxH);\n                        }\n                        imagecopy($iOut, $img, 0, 0, 0, $i * $maxH, $maxW, $maxH);\n                        $funImg($iOut, $newfile);\n                        $newPath = str_replace($storagePath, 'storage',  $newfile);\n                        $arrImgFg[] = ['url' =&gt; $newPath, 'carousel' =&gt; 0];\n                    }\n                    $willToChange[$key] = $arrImgFg;\n                    imagedestroy($img);\n                }\n            }\n        }\n    }\n\n    $offset = 0;\n    $arrKeyOffset = [];\n    foreach ($willToChange as  $key =&gt; $imgList) {\n        $arrKeyOffset[] = $key + $offset;\n       <strong> array_splice($imgListJson, $key + 1 + $offset, 0, $imgList); \/\/ \u63d2\u5165\u5230\u6b64\u4f4d\u7f6e \u4e14\u5220\u96640\u4e2a<\/strong>\n        $offset += count($imgList);\n    }\n\n    foreach ($arrKeyOffset as $key) {\n        unset($imgListJson[$key]);\n    }\n\n    return $imgListJson;\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e1a\u52a1\u8bf4\u660e:\u7531\u4e8eios\u6700\u5927\u652f\u63012048 * 2048&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/log.tanxiaodian.com\/?p=683\">Continue reading<span class=\"screen-reader-text\">\u56fe\u7247\u88c1\u526a<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[121,120],"_links":{"self":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/683"}],"collection":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=683"}],"version-history":[{"count":2,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions"}],"predecessor-version":[{"id":686,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/683\/revisions\/686"}],"wp:attachment":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}