我认为它应该是:

$path = \'myfolder/myimage.png\';
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$ 64 = \'data:image/\' . $type . \'; 64,\' .  64_encode($data);

 

也可以这种方式用 64编码格式表示图像...找到PHP函数file_get_content,然后使用函数 64_encode

并得到结果准备str作为data:" . file_mime_type . " 64_encoded string。在img src属性中使用它。看下面的代码可以帮到你。

// A few settings
$img_file = \'raju.jpg\';

// Read image path, convert to  64 encoding
$imgData =  64_encode(file_get_contents($img_file));

// Format the image SRC:  data:{mime}; 64,{data};
$src = \'data: \'.mime_content_type($img_file).\'; 64,\'.$imgData;

// Echo out a sample image
echo \'<img src=\"\'.$src.\'\">\';
收藏 打印