Reputation: 41
I can successfully get the mp3 ID3 tags out of my mp3 app, using php. I am left with a huge BLOB. I'm sure this is pretty straightforward, but I just need a little help in the right direction. What I'd like to end up with is (BLOB DATA CORRECTED):
$media_year = implode($ThisFileInfo['comments_html']['year']);
$media_genre = implode($ThisFileInfo['comments_html']['genre']);
$media_jpg = [BLOBDATA];
(I know that makes no programming sense, but you get the idea. The first two lines work fine for me, but I don't know how to get the BLOBDATA from the ID3 tags and convert it to a JPG that I can display.)
In another tutorial I see this, but it doesn't connect the dots for me:
[comments] => Array
(
[picture] => Array
(
[0] => Array
(
[data] => <binary data>
[image_mime] => image/jpeg
)
)
)
I loathe asking readers to "do it for me" so, please forgive me. But I've tried every resource I can find. Any help is supremely appreciated.
Upvotes: 4
Views: 17642
Reputation: 638
you can use file_put_contents() to save the id3 image data to a file.
$path = "/Applications/MAMP/htdocs/site/example.mp3"; //example. local file path to mp3
$getID3 = new getID3;
$tags = $getID3->analyze($Path);
if (isset($tags['comments']['picture']['0']['data'])) {
$image = $tags['comments']['picture']['0']['data'];
if(file_put_contents(FCPATH . "imageTest.jpg", $image)) {
echo 'Image Added';
} else {
echo 'Image Not Added';
}
}
or you can display the image in place using
header('Content-Type: image/jpeg');
echo $tags['comments']['picture']['0']['data'];
Upvotes: 2
Reputation: 538
I found an Article which explains the Structure of ID3 Tags. http://www.stagetwo.eu/article/19-MP3-ID3-Tags-Wie-kann-man-die-teile-lesen This should make you able to understand and to parse them. It's in German but maybe the article about the ID3 Tags Structure is also readable with google translator. I like the description of the important bytes and for example the explanation about the SyncSafe integer.
To your Problem it describes how the APIC (Image) Frame is structured.
When you parsed these Structure and you got the bytestream just use imagecreatefromstring($byteStream)
Now you have your image resource out of the MP3 :)
Upvotes: 0
Reputation: 3149
i use getid3 library for this work fine like
<?php
$Path="mp3 file path";
$getID3 = new getID3;
$OldThisFileInfo = $getID3->analyze($Path);
if(isset($OldThisFileInfo['comments']['picture'][0])){
$Image='data:'.$OldThisFileInfo['comments']['picture'][0]['image_mime'].';charset=utf-8;base64,'.base64_encode($OldThisFileInfo['comments']['picture'][0]['data']);
}
?>
<img id="FileImage" width="150" src="<?php echo @$Image;?>" height="150">
in this code i embedded image in to HTML with base64_encode
that you can see
Upvotes: 12