PHP

Convert image to string with PHP

To convert an image file to a string we have to encode image file contents with base64 algorithm.

1
2
3
$image = "it.jpg";
$imgstr = base64_encode(fread(fopen($image, "r"), filesize($image))); 
<img src="data:image/jpg;base64,$imgstr"/>