验证中...
助力高校计算机教育 —— 码云为老师推出免费高校版,高达 200 人的协作团队
获取音频文件信息
原始数据 复制代码
/**
* @param $filename 音乐路径
* @param $file_path 生成的封面图片存放路径
* @param $mp3name 音乐名
* @return array
* author maritni
*/
public function mp3info($filename,$file_path,$mp3name){
//封面图片
$getID3 = new \getID3();
$ThisFileInfo = $getID3 -> analyze($filename);
$cover = null;
$artist = '';
$title = '';
$album = '';
$bitrate = '';
$playtime = '';
$cover_name = '';
$thumb_name = '';
if(isset($getID3 -> info['id3v2'])){
$minfo = $getID3 -> info['id3v2'];
$artist = isset($minfo['comments']['artist']) ? $minfo['comments']['artist'][0] : '';
$title = isset($minfo['comments']['title']) ? $minfo['comments']['title'][0] : '';
$album = isset($minfo['comments']['album']) ? $minfo['comments']['album'][0] : '';
//封面信息
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';
}
}
//将封面信息,存成图片和缩略图文件
if(!is_null($cover)){
$im = imagecreatefromstring($cover);
$newwidth = $newheight = 50;
$thumb = imagecreatetruecolor($newwidth, $newheight);
if($im !== false){
//输出或保存图片
$fileName = $file_path.$mp3name.'_cover.jpeg';
imagealphablending($im, false); //关闭图像的混色模式,
imagesavealpha($im, true);//设置保存 PNG 图像时保存完整的 alpha 通道信息
//生成图片,输出
$resp = imagejpeg($im, $fileName);
//调整图片大小
imagealphablending($im, false); //关闭图像的混色模式,
imagesavealpha($im, true);//设置保存 PNG 图像时保存完整的 alpha 通道信息
$source = imagecreatefromjpeg($fileName);
imagealphablending($source, true); //开启图像的混色模式
list($width, $height, $type, $attr) = getimagesize($fileName);
imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //重采样拷贝部分图像并调整大小
$newFilename = $file_path.$mp3name.'_thumb.jpeg';
$resp = imagejpeg($thumb, $newFilename);
//从内存中释放图像
imagedestroy($im);
imagedestroy($thumb);
$cover_name = $fileName;
$thumb_name = $newFilename;
}
}
// 获取歌曲品质比特率
if(isset($getID3 -> info['audio'])){
$bt = $getID3 -> info['audio'];
$bitrate = isset($bt['bitrate']) ? $bt['bitrate'] : '';
}
// 获取歌曲的时长
if(isset($getID3 -> info['playtime_seconds'])){
$playtime = $getID3 -> info['playtime_seconds'];
}
return $MP3info = [
'cover' => $cover,
'artist' => $artist,
'title' => $title,
'album' => $album,
'bitrate' =>$bitrate,
'playtime' =>$playtime,
'cover_name' => $cover_name,
'thumb_name' =>$thumb_name];
}

评论列表( 0 )

你可以在登录后,发表评论

10_float_left_people 10_float_left_close