Hi,
can you please give an example how to extract the cover/artwork from an mp3 file?
I found this old thread: viewtopic.php?f=11&t=1062
But the option "getID3->option_tags_images" doesn't even exist anymore in the latest version (I didn't find it in the source).
$getID3->info['id3v2']['APIC'] and 'PIC' is always empty when I run the demo.browse.php
I figured I need to call saveAttachment() in getid3.php ?? But what are the correct parameters for such a call - i.e. how do I know the needed offset and length parameter??
Can you please give me an example call of saveAttachment()?
Thanks
Artwork extraction example
-
- User
- Posts:4
- Joined:Tue Sep 20, 2011 4:31 am
- Are you a spambot?:no
-
- getID3() v1 developer
- Posts:1477
- Joined:Fri May 04, 2001 4:00 pm
- Are you a spambot?:no
- Location:Northern Ontario, Canada
- Contact:
Re: Artwork extraction example
Since v1.8.5 all images (from all tag formats) are returned in the constant location [comments][picture], where each entry in the array is a 2-element array of [data] and [image_mime]. So you could do something like this:
edit: the above assumes you're using the latest stable version, which is v1.9.1 at this writing.
Code: Select all
if (!empty($getid3->info['comments']['picture'])) {
foreach ($getid3->info['comments']['picture'] as $key => $picture_array) {
file_put_contents('whatever_filename_' . $key . '.' . str_replace('image/', '', $picture_array['image_mime']), $picture_array['data']);
}
}
-
- User
- Posts:4
- Joined:Tue Sep 20, 2011 4:31 am
- Are you a spambot?:no
Re: Artwork extraction example
Thanks for your fast reply. Do I have to enable anything for this to work?
Because when I run the demo.basic.php and print_r() all the data of $ThisFileInfo there is no picture set under comments (or anywhere else). When I open the same mp3 file at the same location with Winamp I see the artwork. I tested this with a couple mp3's now and the result is always empty. Any ideas?
edit: yes I am using v1.9.1. tested it on apache on a windows 7 and a debian 6 64 bit machine.
edit2: my code looks like this (just the demo.basic.php)
In media players all the tested test.mp3 files have a cover. But getID3 doesn't show anything.
Because when I run the demo.basic.php and print_r() all the data of $ThisFileInfo there is no picture set under comments (or anywhere else). When I open the same mp3 file at the same location with Winamp I see the artwork. I tested this with a couple mp3's now and the result is always empty. Any ideas?
edit: yes I am using v1.9.1. tested it on apache on a windows 7 and a debian 6 64 bit machine.
edit2: my code looks like this (just the demo.basic.php)
Code: Select all
require_once('../getid3/getid3.php');
$getID3 = new getID3;
$filename = 'test.mp3';
$ThisFileInfo = $getID3->analyze($filename);
getid3_lib::CopyTagsToComments($ThisFileInfo);
echo '<pre>'.htmlentities(print_r($ThisFileInfo, true)).'</pre>';
Last edited by Zordon on Tue Sep 20, 2011 4:10 pm, edited 1 time in total.
-
- getID3() v1 developer
- Posts:1477
- Joined:Fri May 04, 2001 4:00 pm
- Are you a spambot?:no
- Location:Northern Ontario, Canada
- Contact:
Re: Artwork extraction example
Do you see the picture(s) under demo.browse.php ? If not, please PM me a link to a sample file that shows this problem.
-
- User
- Posts:4
- Joined:Tue Sep 20, 2011 4:31 am
- Are you a spambot?:no
Re: Artwork extraction example
No I don't see any pictures under demo.browse.php (just all the other data I see with the demo.basic.php).
I'll PM you immediately.
And thank you so much for your fast replies :)
I'll PM you immediately.
And thank you so much for your fast replies :)
-
- getID3() v1 developer
- Posts:1477
- Joined:Fri May 04, 2001 4:00 pm
- Are you a spambot?:no
- Location:Northern Ontario, Canada
- Contact:
Re: Artwork extraction example
Looking through your sample file I'm not convinced that it contains any artwork at all. I've looked through the raw file and there doesn't appear to be anything unusual, no hidden or proprietary tags or anything like that.
Try copying just the MP3 file (no *.ini, no *.jpg, including the hidden *.jpg) to another folder and you'll likely not see the artwork there.
Try copying just the MP3 file (no *.ini, no *.jpg, including the hidden *.jpg) to another folder and you'll likely not see the artwork there.
-
- User
- Posts:4
- Joined:Tue Sep 20, 2011 4:31 am
- Are you a spambot?:no
Re: Artwork extraction example
Yes, you're right. Huge misunderstanding of me. I thought the ID3v2 tag just points to the cover location but not actually includes it.
Ok but where do I get an mp3 to test it now? On your demo page there isn't an mp3 with artwork, is there? http://www.getid3.org/demo/
I tried using demo.write.php to add an artwork, but I get the following error:
Thanks for your great help and sorry for my misunderstanding about artwork tags.
edit. I just changed line 46 of demo.write.php to: $tagwriter->overwrite_tags = true; and now I can add my own artwork tags. -> solved ;)
Ok but where do I get an mp3 to test it now? On your demo page there isn't an mp3 with artwork, is there? http://www.getid3.org/demo/
I tried using demo.write.php to add an artwork, but I get the following error:
I don't need the demo.write.php, just a mp3 file to test and understand how the real artwork tags work.. (and to extract them). Can you please show me such a file?Fatal error: Uncaught exception 'Exception' with message '$this->overwrite_tags=false is known to be buggy in this version of getID3. Will be fixed in the near future, check http://www.getid3.org for a newer version.' in C:\Tools\xampp\htdocs\getid3\getid3\write.php:422 Stack trace: #0 C:\Tools\xampp\htdocs\getid3\getid3\write.php(478): getid3_writetags->MergeExistingTagData('id3v1', Array) #1 C:\Tools\xampp\htdocs\getid3\getid3\write.php(268): getid3_writetags->FormatDataForID3v1() #2 C:\Tools\xampp\htdocs\getid3\demos\demo.write.php(103): getid3_writetags->WriteTags() #3 {main} thrown in C:\Tools\xampp\htdocs\getid3\getid3\write.php on line 422
Thanks for your great help and sorry for my misunderstanding about artwork tags.
edit. I just changed line 46 of demo.write.php to: $tagwriter->overwrite_tags = true; and now I can add my own artwork tags. -> solved ;)
-
- getID3() v1 developer
- Posts:1477
- Joined:Fri May 04, 2001 4:00 pm
- Are you a spambot?:no
- Location:Northern Ontario, Canada
- Contact:
Re: Artwork extraction example
Sadly that demo page is a static copy of the output from v1.6.1 (March 2003)... I really need to update that to be more current...Zordon wrote:Yes, you're right. Huge misunderstanding of me. I thought the ID3v2 tag just points to the cover location but not actually includes it.
Ok but where do I get an mp3 to test it now? On your demo page there isn't an mp3 with artwork, is there? http://www.getid3.org/demo/