我希望创建一个php文件,当调用为html的img标记中的src参数时,该文件将返回mp3歌曲的图像。就像这样:
<img src="/imageReturn.php?song=SongName">为了从mp3文件中获取图像,我使用了getID3库。我的PHP代码:
$song= $_GET["song"];
require_once("getID3-1.9.15/getid3/getid3.php");
$Path=$song.".mp3";
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($Path);
if(isset($OldThisFileInfo['comments']['picture'][0]))
{
$ImageBase='data:'.$OldThisFileInfo['comments']['picture'][0]['image_mime'].';charset=utf-8;base64,'.base64_encode($OldThisFileInfo['comments']['picture'][0]['data']);
}
header('Content-Type: image/jpeg');
echo $ImageBase;问题是我无法获得php显示的图像。怎么修呢?
发布于 2018-05-06 10:21:28
您不必将图像编码为base64,您可以直接对图像数据进行echo。
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($Path);
if(isset($OldThisFileInfo['comments']['picture'][0]))
{
header('Content-Type: ' . $OldThisFileInfo['comments']['picture'][0]['image_mime']);
echo $OldThisFileInfo['comments']['picture'][0]['data'];
die;
}https://stackoverflow.com/questions/50198404
复制相似问题