Reputation: 2716
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>
Upvotes: 1
Views: 1668
Reputation: 11117
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?
Upvotes: 2