我有一个代码可以预览mp3文件中的封面照片。它显示封面照片,但我想将图像导出为.jpg格式如何做到这一点?这是我的代码
require_once('getid3.php');
$getID3 = new getID3;
#$getID3->option_tag_id3v2 = true;
$getID3->analyze("Daayre.mp3");
if (isset($getID3->info['id3v2']['APIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['APIC'][0]['data'];
} elseif (isset($getID3->info['id3v2']['PIC'][0]['data'])) {
$cover = $getID3->info['id3v2']['PIC'][0]['data'];
} else {
$cover = null;
}
if (isset($getID3->info['id3v2']['APIC'][0]['image_mime'])) {
$mimetype = $getID3->info['id3v2']['APIC'][0]['image_mime'];
} else {
$mimetype = 'image/jpeg'; // or null; depends on your needs
}
if (!is_null($cover)) {
header("Content-Type: ".$mimetype);
if (isset($getID3->info['id3v2']['APIC'][0]['image_bytes'])) {
header("Content-Length: ".$getID3->info['id3v2']['APIC'][0]['image_bytes']);
}
echo($cover);
}
如果我写<img src="<?php echo $cover; ?>"/>
,那么它会显示图片。
我想导出图片。
怎么做?
答案 0 :(得分:0)
$cover
内存储了什么?好像你应该只能将$cover
写入文件。试试file_put_contents
,例如:
//If $cover is not a stream or string of data, you may need to make it one.
//For example, using fopen or another method depending on what $cover is
$filename = "somefilename.jpg";
file_put_contents($filename, $cover);
有关file_put_contents
here的更多信息。它还取决于“出口”的含义。您是要将文件发送给用户还是仅将文件存储在计算机/服务器上?