{"id":1323,"date":"2024-01-14T14:53:26","date_gmt":"2024-01-14T06:53:26","guid":{"rendered":"https:\/\/log.tanxiaodian.com\/?p=1323"},"modified":"2024-01-14T14:53:27","modified_gmt":"2024-01-14T06:53:27","slug":"php_%e5%9b%be%e7%89%87%e7%b1%bb%e5%9e%8b%e8%bd%ac%e6%8d%a2%e5%92%8c%e5%b0%ba%e5%af%b8%e5%8e%8b%e7%bc%a9","status":"publish","type":"post","link":"https:\/\/log.tanxiaodian.com\/?p=1323","title":{"rendered":"PHP_\u56fe\u7247\u7c7b\u578b\u8f6c\u6362\u548c\u5c3a\u5bf8\u538b\u7f29"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>if($this->category == 16 &amp;&amp; $suffix != 'gif' &amp;&amp; ($this->force == 2)) {\r\n                $this->file->move($destDir, $fileName);\r\n                $filepathsrc = $destDir . $fileName;\r\n                switch($suffix) {\r\n                    case 'png':\r\n                        $image = imagecreatefrompng($filepathsrc);\r\n                        break;\r\n                    case 'jpg':\r\n                        $image = imagecreatefromjpeg($filepathsrc);\r\n                        break;\r\n                    case 'webp':\r\n                        $image = imagecreatefromwebp($filepathsrc);\r\n                        break;\r\n                }\r\n\r\n                list($width, $height) = getimagesize($filepathsrc);\r\n                $fname = substr($filepathsrc,0, strrpos($filepathsrc, '.'));\r\n                $newfilename = $fname . '.gif';\r\n\r\n                if($width > self::$MAXWLIMIT || $height>self::$MAXWLIMIT) {\r\n                    if($width > $height) {\r\n                        $k = 1;\r\n                    }else{\r\n                        $k = 2;\r\n                    }\r\n                    $newwidth = self::$MAXWLIMIT;\r\n                    $newheight = self::$MAXWLIMIT;\r\n                    if($k == 1){\r\n                        $newheight = round($height\/$width  * $newwidth);\r\n                    }else{\r\n                        $newwidth =  round($width\/$height  * $newheight);\r\n                    }\r\n\r\n\r\n\r\n                }else{\r\n                    $newwidth = $width;\r\n                    $newheight = $height;\r\n                }\r\n                $newImage = imagecreatetruecolor($newwidth, $newheight);\r\n                $color = imagecolorallocatealpha($newImage,255,255,255, 127);\r\n                imagecolortransparent($newImage, $color);\r\n                imagefill($newImage,0,0,$color);\r\n                \/\/ \u5728\u65b0\u7684\u753b\u5e03\u4e0a\u590d\u5236\u8c03\u6574\u540e\u7684\u56fe\u50cf\r\n                imagecopyresampled($newImage, $image, 0, 0, 0, 0,$newwidth, $newheight, $width, $height);\r\n                $res = imagegif($newImage,  $newfilename);\r\n                if ($res) {\r\n                    $filePath = $newfilename;\r\n                    $extgif = 'gif';\r\n                }\r\n                imagedestroy($newImage);\r\n                imagedestroy($image);\r\n\r\n            }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[238,100],"_links":{"self":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/1323"}],"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=1323"}],"version-history":[{"count":1,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions"}],"predecessor-version":[{"id":1324,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=\/wp\/v2\/posts\/1323\/revisions\/1324"}],"wp:attachment":[{"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1323"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1323"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/log.tanxiaodian.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1323"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}