使用getid3(id3v2)将APIC写入mp3文件 [英] writing APIC to mp3 file with getid3 (id3v2)
问题描述
我正在尝试使用getid3将APIC图片写入mp3文件.这是代码;
I am trying to write APIC picture to mp3 file with getid3. here is the code;
$cover = "/home/user/public_html/artwork/cover.jpg";
$TagData['attached_picture'][]=array(
'picturetypeid'=>2, // Cover. More: module.tag.id3v2.php -> function APICPictureTypeLookup
'description'=>'cover', // text field
'mime'=>'image/jpeg', // Mime type image
'data'=>$cover // Image data
);
但是它不起作用.图像大小约为1.5 MB.我应该重新调整大小还是……?
but it doesnt work. image size is around 1.5 MB. should i resize it or sth ?
我在哪里错了?
谢谢
推荐答案
查看他们在其网站上的演示: http://www.getid3.org/source/demo.write.phps
Looking at the demo they have on their website: http://www.getid3.org/source/demo.write.phps
代码段
$fd = fopen($_FILES['userfile']['tmp_name'], 'rb')
$APICdata = fread($fd, filesize($_FILES['userfile']['tmp_name']));
fclose ($fd);
$imagetypes = array(1=>'gif', 2=>'jpeg', 3=>'png');
if (isset($imagetypes[$APIC_imageTypeID])) {
$TagData['attached_picture'][0]['data'] = $APICdata;
$TagData['attached_picture'][0]['picturetypeid'] = $_POST['APICpictureType'];
$TagData['attached_picture'][0]['description'] = $_FILES['userfile']['name'];
$TagData['attached_picture'][0]['mime'] = 'image/'.$imagetypes[$APIC_imageTypeID];
}
似乎数据键需要是图像内容,而不仅仅是图像文件的路径. 因此,在您的情况下,应该是这样的:
Seems like the data key needs to be the image content, not just the path to the image file. So in your case, it should be something like:
$cover = "/home/user/public_html/artwork/cover.jpg";
$fd = fopen($cover, 'rb')
$APICdata = fread($fd, filesize($coverFile));
fclose ($fd);
$TagData['attached_picture'][]=array(
'picturetypeid'=>2, // Cover. More: module.tag.id3v2.php -> function APICPictureTypeLookup
'description'=>'cover', // text field
'mime'=>'image/jpeg', // Mime type image
'data'=>$APICdata // Image data
);
注意:这只是在快速浏览了演示代码之后,我还没有使用此库或测试过此代码.
Note: This is just after a quick glance at the demo code, I have not used this library or tested this code.
这篇关于使用getid3(id3v2)将APIC写入mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!