91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

php中base64轉換為圖片的方法

發布時間:2020-08-31 09:56:18 來源:億速云 閱讀:179 作者:小新 欄目:編程語言

小編給大家分享一下php中base64轉換為圖片的方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

php base64轉換為圖片的方法:首先獲取base64文件;然后設置生成的圖片名字;接著通過if語句判斷是否有逗號;最后設置圖片保存路徑即可。

php中base64轉換為圖片的方法

  • 獲取base64文件
 $image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASIAAAEiCAYAAABdvt+2AAAgAElEQVR4Xuy9B5hlV3Wm/Z58bq6cujpVB3WUWlJ308oERSQMCAVAAkQQYoi2sQcMAzOD5zcG29hjDGYMxhiTDMaYKEAgwMoSKNBqda7uyunmcHL4n32qW0gCLIG6JAR3P0+pq0q39rl37X2+s/Za3/qWJCPHtMdTagFJkhavJ0VIyEgYyKpPV4/MpReexHXXvIWgZOEcvofueBZfMnDVHKphkpNc/OYUsmoQGiNY6hBKvg8zckBT0TWJrGZTntyPPL2HrD9DKpjDDz3cWCGt5Ik9CJQ+vNwaAnccPfIJl51Oo1rk0r/4AVXPe0rt0b5Y2wJSG4iehk1wDIcgRkJB1TQkxWHD5m4uf94Ozn/OiykdGSdd2UdnNIGvaIRqFl2VMJwSUbOCanYQ6P045iCe2omiRchxgBR6FNI6chhAsURU2osZTeEFDYIgIKeoOIHKQtBJ/qRzCcsLxNWHmA41urqHueDP76UV2E+DUdqXfLIWEA+4OI7RdR3f95PvnymjDURPw0rJsnzsqjFxLKOqEh09Er93+U7eeMVL6S4s574ffp+eYJRccBSXApqZwZQDKB3BDH3cWMcz0rhGL5E5hKNk6T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d48Ac3o8czbDxJI230Y+kp6FqDLQ8hlYvENNDieeZrJW7a2+Tvvj9PGIfExCAdSwE/czLBj7sG7Rf85lmgDURP8ZqoqprwPDzPIwgjzFTEBZeu59WvfjWnbj2f+pEigR9jtXxkySBf6KTieklK9jiINVs2mbDG0ds+Q3P0Doa7c6jZVSjZAqGqM3Fkkq0jw1jpEeLaGD/8/Be58oJV+P4RAn0VVaWXMD2MbBZQUhlCv4niFWksjGI1q1zz//aDomEFLrEUkfCd4mdG9uUpXs725U6QBdpAdI";
  • 設置生成的圖片名字
 $imageName = "25220_".date("His",time())."_".rand(1111,9999).'.png';
  • 判斷是否有逗號 如果有就截取后半部分
if (strstr($image,",")){    $image = explode(',',$image);    $image = $image[1];
}
  • 設置圖片保存路徑
$path = "tmp/signImage/".date("Ymd",time());
  • 判斷目錄是否存在 不存在就創建 并賦予777權限
if (!is_dir($path)){ //判斷目錄是否存在 不存在就創建
   mkdir($path,0777,true);
}
  • 拼接路徑和圖片名稱
 $imageSrc=  $path."/". $imageName;
  • 生成圖片 返回的是字節數
 $r = file_put_contents(ROOT_PATH ."public/".$imageSrc, base64_decode($image));
  • 判斷圖片是否生成成功
if (!$r) {   return json(['data'=>null,"code"=>1,"msg"=>"圖片生成失敗"]);
 }else{   return json(['data'=>1,"code"=>0,"msg"=>"圖片生成成功"]);
}
  • 完整代碼如下
$image="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASIAAAEiCAYAAABdvt+2AAAgAElEQVR4Xuy9B5hlV3Wm/Z58bq6cujpVB3WUWlJ308oERSQMCAVAAkQQYoi2sQcMAzOD5zcG29hjDGYMxhiTDMaYKEAgwMoSKNBqda7uyunmcHL4n32qW0gCLIG6JAR3P0+pq0q39rl37X2+s/Za3/qWJCPHtMdTagFJkhavJ0VIyEgYyKpPV4/MpReexHXXvIWgZOEcvofueBZfMnDVHKphkpNc/OYUsmoQGiNY6hBKvg8zckBT0TWJrGZTntyPPL2HrD9DKpjDDz3cWCGt5Ik9CJ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nl3zwVqrxMye28DQsX/uSS2CBNhAtgVEfb8qHPaLIRJIclq9Wef4LzuBlL7uC+cMRfqPJSatW0Jybw1RllM4BysUQXc1hpmViq4QzvRtK95I3A0JS6FGGpqLhGCkK+R5kx6dhTZKxF0gHVcbHpxlYtRrbS5HvLBAiY9khWqtBINnE8RyjlYD3fHWeA5U2ED3eGrb//4m1QBuITqw9H3c2kWL9GRAZZPMSp+8aYPPWVbz1zX/E/jvHsZotlvcNIQURuqbTkjTsZoSu6sgEzM9MsywXML/7y/SYNrqWQyNPJQqQC3k6st3YFYv0yo0444d48Ac3o8czbDxJI230Y+kp6FqDLQ8hlYvENNDieeZrJW7a2+Tvvj9PGIfExCAdSwE/czLBj7sG7Rf85lmgDURP8ZqoqprwPDzPIwgjzFTEBZeu59WvfjWnbj2f+pEigR9jtXxkySBf6KTieklK9jiINVs2mbDG0ds+Q3P0Doa7c6jZVSjZAqGqM3Fkkq0jw1jpEeLaGD/8/Be58oJV+P4RAn0VVaWXMD2MbBZQUhlCv4niFWksjGI1q1zz//aDomEFLrEUkfCd4mdG9uUpXs725U6QBdpAdI";            $imageName = "25220_".date("His",time())."_".rand(1111,9999).'.png';            if (strstr($image,",")){                $image = explode(',',$image);                $image = $image[1];
            }            $path = "tmp/signImage/".date("Ymd",time());            if (!is_dir($path)){ //判斷目錄是否存在 不存在就創建
                mkdir($path,0777,true);
            }            $imageSrc=  $path."/". $imageName;  //圖片名字

            $r = file_put_contents(ROOT_PATH ."public/".$imageSrc, base64_decode($image));//返回的是字節數
            if (!$r) {                return json(['data'=>null,"code"=>1,"msg"=>"圖片生成失敗"]);
            }else{                return json(['data'=>1,"code"=>0,"msg"=>"圖片生成成功"]);
            }

以上是php中base64轉換為圖片的方法的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

php
AI

延长县| 和平县| 天台县| 宜城市| 遂溪县| 林州市| 庆元县| 鞍山市| 库车县| 都匀市| 茶陵县| 明溪县| 噶尔县| 郑州市| 普定县| 大庆市| 兴仁县| 丰镇市| 诏安县| 水富县| 巧家县| 浑源县| 于都县| 许昌县| 兴宁市| 安阳市| 武义县| 珲春市| 盐边县| 襄城县| 无为县| 广德县| 新巴尔虎右旗| 濉溪县| 宁城县| 黑河市| 镇巴县| 金堂县| 怀宁县| 玛曲县| 曲麻莱县|