简体   繁体   中英

convert html image to base64

i have application to send email. library used swift mailer. i have generated html string for sending email which contains various tag including tag can i convert that img src tag to bas64 image

for ex

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

to

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

Yes you can. You just have to convert the image in base64 using base64_encode() function.

$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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM