php base64转图片
时间: 2023-07-06 07:20:16 浏览: 116
可以使用以下代码将 Base64 编码转换为图片并保存:
```php
<?php
// Base64 编码字符串
$base64_string = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAPUExURf///////9KfPb6+Ojr6+jm5uXk5eXj4+Pf39/ezs7Ojo6Nra2tnZ2dmZmZiYmJhYWFgYGBdXV1ZWVlZSUlJiYmIiIhISEgICAgHx8fEBAQDw8PDg4ODAwMCwoKChEREQAAAGtJREFUGNNjYBgFOwAAGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBkYGBoYGBgYjMAMRwJYdM4RfjAAAAAElFTkSuQmCC';
// 去掉前缀并解码
$base64_string = str_replace('data:image/png;base64,', '', $base64_string);
$base64_string = str_replace(' ', '+', $base64_string);
$image_data = base64_decode($base64_string);
// 保存图片
file_put_contents('image.png', $image_data);
?>
```
这段代码将 Base64 编码字符串中的前缀 `data:image/png;base64,` 去掉,然后解码得到图片数据。最后将图片数据保存为 `image.png` 文件。如果需要将其他格式的 Base64 编码转换为图片,只需要替换前缀即可。
阅读全文
相关推荐











