Artwork extraction example

Locked
Zordon
User
Posts: 4
Joined: Tue Sep 20, 2011 4:31 am
Are you a spambot?: no

Artwork extraction example

Post by Zordon » Tue Sep 20, 2011 4:37 am

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

James Heinrich
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

Post by James Heinrich » Tue Sep 20, 2011 1:06 pm

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:

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']);
  }
}
edit: the above assumes you're using the latest stable version, which is v1.9.1 at this writing.

Zordon
User
Posts: 4
Joined: Tue Sep 20, 2011 4:31 am
Are you a spambot?: no

Re: Artwork extraction example

Post by Zordon » Tue Sep 20, 2011 4:00 pm

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)

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>';
In media players all the tested test.mp3 files have a cover. But getID3 doesn't show anything.
Last edited by Zordon on Tue Sep 20, 2011 4:10 pm, edited 1 time in total.

James Heinrich
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

Post by James Heinrich » Tue Sep 20, 2011 4:03 pm

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.

Zordon
User
Posts: 4
Joined: Tue Sep 20, 2011 4:31 am
Are you a spambot?: no

Re: Artwork extraction example

Post by Zordon » Tue Sep 20, 2011 4:11 pm

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 :)

James Heinrich
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

Post by James Heinrich » Tue Sep 20, 2011 5:05 pm

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.

Zordon
User
Posts: 4
Joined: Tue Sep 20, 2011 4:31 am
Are you a spambot?: no

Re: Artwork extraction example

Post by Zordon » Tue Sep 20, 2011 5:29 pm

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:
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
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?
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 ;)

James Heinrich
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

Post by James Heinrich » Tue Sep 20, 2011 6:36 pm

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/
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...

Locked