php - 如何将图像转换为 Base64 编码

标签 php image base64

如何将图像从 URL 转换为 Base64 编码?

最佳答案

我认为应该是:

$path = 'myfolder/myimage.png';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);

关于php - 如何将图像转换为 Base64 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3967515/

相关文章:

php - 如何根据 <select> 更改内容?

javascript - 如何启用文本字段以使用 javascript 和 html 进行编辑?

java Files.readAllBytes(image.png) 不起作用

c++ - 如何使用openssl进行base 64解码?

Swift 将 base64 字符串(即 docx 文件)转换为 (nsdata)

javascript - 从javascript中删除双引号

用于创建 8 个字符长散列的 PHP 函数([a-z] = 不允许使用数字)

c# - WCF 图像序列化

html - 在中间的图像上添加文本

css - 使用 base64 svg 图片作为 css 内容源