【问题标题】:convert html image to base64将html图像转换为base64
【发布时间】:2013-12-04 11:53:04
【问题描述】:

我有发送电子邮件的申请。图书馆使用了 swift mailer。 我已经生成了用于发送电子邮件的 html 字符串 其中包含各种标签,包括标签 我可以将该 img src 标签转换为 bas64 图像吗

前任

   <html>
some txt+html ...
<img src="some-path/image.jpg">
some text+html ..
</html>

  <html>
    some txt+html ...
    <img src="data:image/jpg;base64, $base64_code_of_image.jpg ">
    some text+html ..
    </html>

【问题讨论】:

    标签: php image base64


    【解决方案1】:

    是的,你可以。您只需使用 base64_encode() 函数将图像转换为 base64。

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

    How to convert an image to base64 encoding?

    【讨论】:

    • 输入会是包含图片路径的html字符串,不知道他们的位置,那怎么办
    猜你喜欢
    • 2015-12-09
    • 2013-07-01
    • 2014-04-06
    • 2017-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-24
    相关资源
    最近更新 更多