一、图片文件转base64
function imgFileToBase64() { //$img = 'D:\xampp\git-new\wshifu-apps\service\assets\logo_new.png';//本地图片 $img = 'https://qncdn.wanshifu.com/237f4f2eebd1aea845e014a1634cad36?imageView2/0/interlace/1/ignore-error/1';// 远程图片 $base64_image = ''; if (stripos($image_file, 'http') !== false) {//如果是远程图片先下载到本地 $stream_content = file_get_contents($image_file); $image_file = realpath("./") . '/file.jpg'; //print_r($image_file);exit; file_put_contents($image_file, $stream_content); } if(file_exists($image_file)){ $img_file_size = filesize($image_file); $img_file_type = getimagesize($image_file); $img_stream_data = fread(fopen($image_file, 'r'), $img_file_size); $base64_image = 'data:' . $img_file_type['mime'] . ';base64,' . base64_encode($img_stream_data); //$base64_image = 'data:' . $img_file_type . ';base64,' . base64_encode(chunk_split($img_stream_data));//chunk_split切割字符串 }else { $base64_image = '图片不存在'; } echo '<img src="' . $base64_img . '" />'; } imgFileToBase64();
function imgBase64ToFile() { $dir_path = realpath("./") ; if (!is_dir($dir_path)) { mkdir($dir_path, 0777); } $base64_image_content = 'data:image/jpg;base64,\/9j\/4AAQSkZJRgABAgAAAQABAAD\/\/gAKSFMwMQILAAAvBgCk+gD\/2wBDAAsHCAkIBwsJCQkMCwsNEBsSEA8PECEYGRQbJyIpKCYiJiUrMT41Ky47LyUmNkk3O0BCRUZFKjRMUktDUT5ERUP\/2wBDAQsMDBAOECASEiBDLCYsQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQ0P\/wAARCADcALIDASIAAhEBAxEB\/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL\/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5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qH1QcD3GcfpV+mQxiKJIlJIRQoz7U+gAqjrcxh099pALnZ+fX9KvVlXYEmu2qPkqE3AZ6Hk5\/QflQBesIDb2cURyCF5BPQnk\/rU9FFAGNrug6HqCmTU7WFmA\/1p4f8K8yv\/hld3TTTaRclrYHhZTmQ+1epagv2jVbe1kY+SV3FQcZPP8AhWkiJGoVFCqOgAwKAPCovAurWs\/+kWVxjy9\/7qPzOfL\/AMaojwtrVxeXbx6VcOvIBWOQj86+gLp2jtpXU4ZUJB98VW0VFXT0IGCxJPuc4\/pQB41afDDxLN5YktoIQ\/G4yf6vHtXS2Xww0+wu7SO9uZb2Yn50jGxAM9h+f5V6dWbp\/wC91O8mbhlOwY6Y6f8AsooAtWlrDZ20cFrEkUUQwI0qxRRQBTkH2nUQhyY7cBiAcfOemfXin3t6lqFUKZJW+6g6moLJtmny3YA8x98h44zzx9Kh0Y\/aLie4kAMnGD6Zz0oAntLIy7bm8zJKR91gMAduP89ap6hLukuGbnJESYPGAcnt64\/PvWxO5jgkkXGVUkZ9hWVFGv2mwiydoj8zr35P9KANWFPKhSPOdqhc+uKhubkiT7PAN8zD14T3NOv5XgtJJExuGMZ+uKSxjVIFkAy8oDu3ck80AV\/7IhPLyysx6nI5P5UVoUUAf\/\/Z" '; if (!$base64_image_content || !$dir_path) { return FALSE; } $result = array(); $new_file = ''; if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $base64_image_content, $result)) { if (!empty($result[2])) { $type = $result[2]; $new_file = $dir_path . time() . ".{$type}"; file_put_contents($new_file, base64_decode(str_replace($result[1], '', $base64_image_content))); } } print_r($new_file); echo '<img src=".'.$new_file.'"/>'; } imgBase64ToFile();