1

I tried to write a php script to get cover image and use it as cover image for mp3 file using getid3 php but the cover image is not showing up in media players.

The cover image is showing in windows folders but not in media players icon badge... Also not showing up on google play music on android.

Belows the code.

<?php
$scr1=$_POST['search1'];
$op90=$_POST['search2'];
$kat=$_POST['search3'];
$album=$_POST['search4'];
$genre=$_POST['search5'];
$TextEncoding = 'UTF-8';
$albumPath = "../../image/".$scr1.".jpg"; // path to your image


require_once("../getid3/getid3.php");
// Initialize getID3 engine
$getID3 = new getID3;
$getID3->setOption(array('encoding'=>$TextEncoding));

require_once("../getid3/write.php");
// Initialize getID3 tag-writing module
$tagwriter = new getid3_writetags;
$tagwriter->filename = '../../../public_html/song/'.$op90.'.mp3';
$filename='../../../public_html/song/'.$op90.'.mp3';
//$tagwriter->tagformats = array('id3v1', 'id3v2.3');
$tagwriter->tagformats = array('id3v2.3');
$ThisFileInfo = $getID3->analyze($filename); 
// set various options (optional)
$tagwriter->overwrite_tags    = true;  // if true will erase existing tag data and write only passed data; if false will merge passed data with existing tag data (experimental)
$tagwriter->remove_other_tags = false; // if true removes other tag formats (e.g. ID3v1, ID3v2, APE, Lyrics3, etc) that may be present in the file and only write the specified tag format(s). If false leaves any unspecified tag formats as-is.
$tagwriter->tag_encoding      = $TextEncoding;
$tagwriter->remove_other_tags = true;

// populate data array
$TagData = array(
    'title'         => array($op90),
    'artist'        => array($kat),
    'album'         => array($album),
    'year'          => array($ThisFileInfo['comments_html']['year'][0]),
    'genre'         => array($genre),
    'comment'       => array($ThisFileInfo['comments_html']['comment'][0]),
    'track'         => array($ThisFileInfo['comments_html']['track'][0]),
);
$fd = fopen($albumPath, 'rb');
$APICdata = fread($fd, filesize($albumPath));
fclose($fd);

if($APICdata) {
    $TagData += array(
        'attached_picture' => array(0 => array(
            'data'          => $APICdata,
            'picturetypeid' => '0x03',
            'description'   => 'cover',
            'mime'          => image_type_to_mime_type(@$albumExifType)
        ))
    );
}



$tagwriter->tag_data = $TagData;

// write tags
if ($tagwriter->WriteTags()) {if (!empty($tagwriter->warnings)) {}} else {}
wittich
  • 2,079
  • 2
  • 27
  • 50
Tanish
  • 37
  • 8
  • You need to provide a **result** MP3 as output from your code. Then we can check what's wrong with the tag bytes and advise. Save this if you need a [**free MP3 file**](http://www.orangefreesounds.com/wp-content/uploads/2017/07/Old-phone-ringing.mp3). Then add ID3 with your code and give uploaded link back here. – VC.One Jul 22 '17 at 17:11
  • 2
    Thanks for commenting , but i finnaly found the problem , just have to set 'picturetypeid' => '0x03' to 'picturetypeid' => '03', as it is the code for cover image , and now the mp3 are working great – Tanish Jul 22 '17 at 18:30

0 Answers0