# Extract Album Art

**URL:** https://forum.kirupa.com/t/extract-album-art/332394
**Category:** flash
**Created:** [May 22, 2014, 10:45am UTC](https://forum.kirupa.com/t/extract-album-art/332394 "2014-05-22T10:45:11Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![scottiescotsman](https://avatars.discourse-cdn.com/v4/letter/s/ac91a4/32.png) [@scottiescotsman](https://forum.kirupa.com/u/scottiescotsman)
#### Post date: [May 22, 2014, 10:45am UTC](https://forum.kirupa.com/t/extract-album-art/332394/1 "2014-05-22T10:45:11Z")

</div>

Hi guys 🙂  
What it is I am finding difficulty with is extracting the album art from a mp3 file.  
I have tried to do it in FLASH, to no avail.  
I have now turned to PHP and unknown to me the PHP code that I use has the capability to extract the exact data that I need from the mp3 file.  
This is the code I use at present to generate the XML playlist.

```php

<?php
require_once('getid3/getid3.php');
$dir = $_GET['folder'];
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
$getID3 = new getID3;
$DirectoryToScan = $dir;
$dirHandle = opendir($dir);
$strIsNull = "not found";
$i = 0;
while (($file = readdir($dirHandle)) !== false) {
$FullFileName = realpath($dir.'/'.$file);
if ((substr($FullFileName, 0, 1) != '.') && is_file($FullFileName)) {
$i++;
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($DirectoryToScan.'/'.$i.'.mp3');
getid3_lib::CopyTagsToComments($ThisFileInfo);
$xmlBody .= '<song>';
         
 /// SONG.NUMBER ///
 $xmlBody .= '<songNumber>' . $i . '</songNumber>
   
 /// SONG.URL ///            
 <songURL>' . basename($ThisFileInfo['filenamepath']) . '</songURL>
   
 /// SONG.ARTIST ///
 <songArtist>' . (!empty($ThisFileInfo['comments_html']['artist']) ? implode('<br>',$ThisFileInfo['comments_html']['artist']) : $strIsNull) . '</songArtist>
 /// SONG.TITLE ///
 <songTitle>' . (!empty($ThisFileInfo['comments_html']['title']) ?implode('<br>', $ThisFileInfo['comments_html']['title']) : $strIsNull) . '</songTitle>
 /// SONG.BITRATE ///
 <songBitrate>' . round($ThisFileInfo['audio']['bitrate'] / 1000) . '</songBitrate>
 /// SONG.DURATION ///
 <songDuration>' . $ThisFileInfo['playtime_string'] . '</songDuration>';
$xmlBody .= '</song>';
}
}
$xmlBody .= "</XML>";
header('Content-type: text/xml');
echo $xmlBody;
?>

```

All I want to do as it reads the id3tag I want it to save the album art to a file ie… 1.jpg 2.jpg  
Here is the code I have tried

```php

$i = 0;
while (($file = readdir($dirHandle)) !== false) {
$FullFileName = realpath($dir.'/'.$file);
if ((substr($FullFileName, 0, 1) != '.') && is_file($FullFileName)) {
$i++;
set_time_limit(30);
$ThisFileInfo = $getID3->analyze($DirectoryToScan);
if(isset($ThisFileInfo['comments']['picture'][0])){$Image='data:'.$ThisFileInfo['comments']['picture'][0]['image_mime'].';charset=utf-8;base64,'.base64_encode($ThisFileInfo['comments']['picture'][0]['data']);
}
file_put_contents($DirectoryToScan+"/ALBUMART/"+ $i + ".jpg", $image);
}
}

```

I know its wrong but hope someone can help 🙂

Thanks  
Steven
