1

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>
r.vengadesh
  • 1,721
  • 3
  • 20
  • 36
Dhiraj Wakchaure
  • 2,596
  • 6
  • 21
  • 37

1 Answers1

2

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?

Community
  • 1
  • 1
TheEwook
  • 11,037
  • 6
  • 36
  • 55