Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Get MP3 Album Art with MP3::Tag

by true (Pilgrim)
on Jul 21, 2005 at 00:59 UTC ( [id://476678]=note: print w/replies, xml ) Need Help??


in reply to Get MP3 Album Art with MP3::Tag

You almost had it. Below example works for me. Set binmode to your outfit after you open the handle. Also, you don't need to print the content-type header unless you are printing to STDOUT (like through a browser).
use MP3::Tag; my $mp3 = MP3::Tag->new("withimage.mp3") or die "no File"; # Get the tags from the MP3 $mp3->get_tags; $id3v2 = $mp3->{ID3v2}; # Get the APIC frame from the Tag (The Image) which # returns a hash ref my $Pic = $id3v2->get_frame("APIC"); # returns open (SAVE, ">out.jpg"); binmode SAVE; print SAVE $Pic->{_Data}; close SAVE;
jtrue

Replies are listed 'Best First'.
Re^2: Get MP3 Album Art with MP3::Tag
by allyc (Scribe) on Jul 21, 2005 at 09:06 UTC
    Thanks for the reply!

    I was hoping to be able to print out to a browser directly to save having to create files?

    I thought that the following would achieve this, but when loaded from a Web Server the image only shows as the Red X , meaning it is corrupt.

    print "Content-type: image/jpeg\n\n"; print $Pic->{_Data};

    Any ideas? I will try the output to a file later on to see if I can get any further.

    Alistair

      You have to set binmode to STDOUT just like you did to the file. This example works off Windows running Apache2 and ActiveState perl 5.8
      #!C:/Perl/bin/perl use MP3::Tag; my $mp3 = MP3::Tag->new("withimage.mp3") or die "no File"; $mp3->get_tags; $id3v2 = $mp3->{ID3v2}; my $Pic = $id3v2->get_frame("APIC"); # returns print "Content-type:image/jpeg\r\n\r\n"; binmode STDOUT; print STDOUT $Pic->{_Data};
      jtrue
        Thank you so much jtrue!

        The penny finaly drops.... should have realised that I needed to set binmode on STDOUT as well.... oh well we live and learn!

        Thank you so much for your help

        Al

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://476678]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-28 21:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found