{"id":178,"date":"2010-05-31T04:55:11","date_gmt":"2010-05-31T10:55:11","guid":{"rendered":"http:\/\/rrbits.com\/epb\/?p=178"},"modified":"2011-02-06T17:41:24","modified_gmt":"2011-02-06T23:41:24","slug":"embed-album-art-into-an-mp3-with-php","status":"publish","type":"post","link":"https:\/\/rrbits.com\/epb\/2010\/05\/31\/embed-album-art-into-an-mp3-with-php\/","title":{"rendered":"Embed Album Art into an MP3 with PHP"},"content":{"rendered":"<p>An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP.\u00a0 Once you have it, you can use a script like this to add artwork to an MP3:<\/p>\n<pre>$mp3 = new KTaglib_MPEG_File('2.mp3');\r\n$idv2 = $mp3-&gt;<a href=\"http:\/\/www.php.net\/manual\/en\/mpegfile.getId3v2Tag.php\">getID3v2Tag<\/a>(true);\r\n$album = new KTaglib_ID3v2_AttachedPictureFrame();\r\n$album-&gt;setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover);\r\n$album-&gt;setPicture('testalbum.jpg');\r\n$album-&gt;setMimeType('image\/jpeg');\r\n$idv2-&gt;addFrame($album);\r\n$mp3-&gt;save();<\/pre>\n<p>Assuming no exceptions are thrown, this should allow you to set an image of your choosing as a FrontCover image\u00a0 (of course replacing my example values with your own real values), consult the <a href=\"http:\/\/www.php.net\/manual\/en\/book.ktaglib.php\">KTaglib documentation<\/a> for more details and check &#8220;Predefined Constants&#8221; for the other image types.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP.\u00a0 Once you have it, you can use a script like this to add artwork to an MP3: $mp3 = new KTaglib_MPEG_File(&#8216;2.mp3&#8217;); $idv2 = $mp3-&gt;getID3v2Tag(true); $album = new KTaglib_ID3v2_AttachedPictureFrame(); $album-&gt;setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover); $album-&gt;setPicture(&#8216;testalbum.jpg&#8217;); $album-&gt;setMimeType(&#8216;image\/jpeg&#8217;); $idv2-&gt;addFrame($album);&#8230;  <a class=\"excerpt-read-more\" href=\"https:\/\/rrbits.com\/epb\/2010\/05\/31\/embed-album-art-into-an-mp3-with-php\/\" title=\"ReadEmbed Album Art into an MP3 with PHP\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31],"tags":[127,181,4262],"class_list":["post-178","post","type-post","status-publish","format-standard","hentry","category-php","tag-metadata","tag-mp3","tag-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/comments?post=178"}],"version-history":[{"count":8,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/178\/revisions"}],"predecessor-version":[{"id":314,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/posts\/178\/revisions\/314"}],"wp:attachment":[{"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/media?parent=178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/categories?post=178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rrbits.com\/epb\/wp-json\/wp\/v2\/tags?post=178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}