Random Renegade Bits

  • Home
  • Zombinanza!

Embed Album Art into an MP3 with PHP

Posted May 31st, 2010 by epb & filed under php.

An odd quest perhaps: but adding album art to an MP3 (in ID3 tags) is readily doable with the KTaglib extension for PHP.  Once you have it, you can use a script like this to add artwork to an MP3:

$mp3 = new KTaglib_MPEG_File('2.mp3');
$idv2 = $mp3->getID3v2Tag(true);
$album = new KTaglib_ID3v2_AttachedPictureFrame();
$album->setType(KTaglib_ID3v2_AttachedPictureFrame::FrontCover);
$album->setPicture('testalbum.jpg');
$album->setMimeType('image/jpeg');
$idv2->addFrame($album);
$mp3->save();

Assuming no exceptions are thrown, this should allow you to set an image of your choosing as a FrontCover image  (of course replacing my example values with your own real values), consult the KTaglib documentation for more details and check “Predefined Constants” for the other image types.

Tags: metadata, mp3, php

Baby Aisha

Help Aisha and Chefi get to a better place

Archives

  • March 2017
  • February 2017
  • January 2017
  • September 2016
  • September 2014
  • August 2014
  • May 2014
  • February 2014
  • December 2013
  • September 2013
  • August 2013
  • May 2013
  • February 2013
  • December 2012
  • September 2012
  • June 2012
  • February 2012
  • January 2012
  • October 2011
  • April 2011
  • February 2011
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • June 2010
  • May 2010
  • March 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • February 2009
  • September 2008
  • August 2008
  • December 2007
  • August 2007

Tags

actionscript android bash bfxr CherryPad code color comic css currencies danbooru encryption GIMP Godot hopefully_that_made_sense html ImageMagick image manipulation javascript linux ludumdare marisa mcrypt metadata mounting mp3 pdf php pipes problem rprng rss script-a-day shell slightly random stack overflow svg tcpdf Tools touhou vdi vhd web wikipedia xslt

About

A random blog where I write about my programming projects, Linux, the occasional video game and anything else that comes to mind.

© 2025 Random Renegade Bits. RRBits Portal