{"id":36,"date":"2023-08-01T14:44:02","date_gmt":"2023-08-01T06:44:02","guid":{"rendered":"http:\/\/www.meihuaan.cn\/?p=36"},"modified":"2023-08-01T14:44:02","modified_gmt":"2023-08-01T06:44:02","slug":"php%e4%bf%9d%e5%ad%98%e8%bf%9c%e7%a8%8b%e5%9b%be%e7%89%87%e6%94%b9%e5%8f%98%e5%b0%ba%e5%af%b8%ef%bc%8cjpg%e8%bd%acpng%ef%bc%8c%e8%a3%81%e5%89%aa%e5%9c%86%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/www.meihuaan.cn\/index.php\/2023\/08\/01\/php%e4%bf%9d%e5%ad%98%e8%bf%9c%e7%a8%8b%e5%9b%be%e7%89%87%e6%94%b9%e5%8f%98%e5%b0%ba%e5%af%b8%ef%bc%8cjpg%e8%bd%acpng%ef%bc%8c%e8%a3%81%e5%89%aa%e5%9c%86%e5%bd%a2\/","title":{"rendered":"php\u4fdd\u5b58\u8fdc\u7a0b\u56fe\u7247\u6539\u53d8\u5c3a\u5bf8\uff0cJPG\u8f6cPNG\uff0c\u88c1\u526a\u5706\u5f62"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\/\/$radius\u8bbe\u7f6e\u5706\u89d2\u5f27\u5ea6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function getyuan(){<br>$radius = 20;<br>$img = imagecreatetruecolor($radius, $radius);<br>$bgcolor = imagecolorallocate($img, 255, 255, 255);<br>$fgcolor = imagecolorallocate($img, 0, 0, 0);<br>imagefill($img, 0, 0, $bgcolor);<br>imagefilledarc($img, $radius, $radius, $radius*2, $radius*2,<br>180, 270, $fgcolor, IMG_ARC_PIE);<br>imagecolortransparent($img, $fgcolor);<br>return $img;<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function put_file_from_url_content($url, $saveName, $path) {<br>\/\/ \u8bbe\u7f6e\u8fd0\u884c\u65f6\u95f4\u4e3a\u65e0\u9650\u5236<br>set_time_limit ( 0 );<br><br>$url = trim ( $url );<br>$curl = curl_init ();<br>\/\/ \u8bbe\u7f6e\u4f60\u9700\u8981\u6293\u53d6\u7684URL<br>curl_setopt ( $curl, CURLOPT_URL, $url );<br>\/\/ \u8bbe\u7f6eheader<br>curl_setopt ( $curl, CURLOPT_HEADER, 0 );<br>\/\/ \u8bbe\u7f6ecURL \u53c2\u6570\uff0c\u8981\u6c42\u7ed3\u679c\u4fdd\u5b58\u5230\u5b57\u7b26\u4e32\u4e2d\u8fd8\u662f\u8f93\u51fa\u5230\u5c4f\u5e55\u4e0a\u3002<br>curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );<br>\/\/ \u8fd0\u884ccURL\uff0c\u8bf7\u6c42\u7f51\u9875<br>$file = curl_exec ( $curl );<br>\/\/ \u5173\u95edURL\u8bf7\u6c42<br>curl_close ( $curl );<br>\/\/ \u5c06\u6587\u4ef6\u5199\u5165\u83b7\u5f97\u7684\u6570\u636e<br>$filename = $path . $saveName;<br>$write = @fopen ( $filename, &#8220;w&#8221; );<br>if ($write == false) {<br>return false;<br>}<br>if (fwrite ( $write, $file ) == false) {<br>return false;<br>}<br>if (fclose ( $write ) == false) {<br>return false;<br>}<br>}<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$url=\u201cwww.xxx.com\u201d;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">$file2=\u201cheadimg\/xxx.png\u201d\uff1b\/\/\u7b2c\u4e00\u6b21\u4fdd\u5b58\u540e\u8def\u5f84<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">put_file_from_url_content($url, &#8220;xxx.png&#8221;, &#8220;headimg\/&#8221;);\/\/\u8fdc\u7a0b\u56fe\u7247\u5730\u5740\uff0c\u4fdd\u5b58\u56fe\u7247\u7684\u540d\u5b57\uff0c\u4fdd\u5b58\u6587\u4ef6\u5939<br>list($width, $height) = getimagesize($file2);<br>$new_width = 40;<br>$new_height = 40;<br>$image_wp = imagecreatetruecolor($new_width, $new_height);<br>$image = imagecreatefromjpeg($file2);<br>imagecopyresampled($image_wp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);<br>imagejpeg($image_wp, $file2, 75);<br>imagedestroy($image_wp);<br>\/**<br>* \u751f\u6210\u5706\u5f62\u56fe<br>*\/<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\/\/ load the source image<br>$src_image = imagecreatefromjpeg($file2);<br>if ($src_image === false) {<br>die(&#8216;Sorry, can\/t load the image&#8217;);<br>}<br>$image_width = imagesx($src_image);<br>$image_height = imagesy($src_image);<br>if($image_width &lt; $image_height){<br>$imageSize = $image_width;<br>}else{<br>$imageSize = $image_height;<br>}<br><br><br>\/\/ create a new image, with src_width, src_height, and fill it with transparent color<br>$image = imagecreatetruecolor($imageSize, $imageSize);<br>$trans_color = imagecolorallocate($image, 255, 255, 255);<br>imagefill($image, 0, 0, $trans_color);<br><br>\/\/ then overwirte the source image to the new created image<br>imagecopymerge($image, $src_image, 0, 0, 0, 0, $imageSize, $imageSize, 100);<br><br>\/\/ then just copy all the rounded corner images to the 4 corners<br>$radius = 20;<br>\/\/ lt<br>$lt_corner = getyuan();<br>imagecopymerge($image, $lt_corner, 0, 0, 0, 0, $radius, $radius, 100);<br>\/\/ lb<br>$lb_corner = imagerotate($lt_corner, 90, $trans_color);<br>imagecopymerge($image, $lb_corner, 0, $imageSize &#8211; $radius, 0, 0,<br>$radius, $radius, 100);<br>\/\/ rb<br>$rb_corner = imagerotate($lt_corner, 180, $trans_color);<br>imagecopymerge($image, $rb_corner, $imageSize &#8211; $radius, $imageSize<br>&#8211; $radius, 0, 0, $radius, $radius, 100);<br>\/\/ rt<br>$rt_corner = imagerotate($lt_corner, 270, $trans_color);<br>imagecopymerge($image, $rt_corner, $imageSize &#8211; $radius, 0, 0, 0, $radius, $radius, 100);<br><br>\/\/ set the transparency<br>imagecolortransparent($image,$trans_color);<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><br>imagepng($image, $file2);<br>imagedestroy($image);<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/\/$radius\u8bbe\u7f6e\u5706\u89d2\u5f27\u5ea6 function getyuan(){$radius = 20;$img =  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":1,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":37,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/posts\/36\/revisions\/37"}],"wp:attachment":[{"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.meihuaan.cn\/index.php\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}