setting album art of a mp3 with php

前端 未结 9 1887
花落未央
花落未央 2021-01-04 16:04

I am looking for the best or any way to set the Album Art of mp3s using PHP.

Suggestions?

9条回答
  •  佛祖请我去吃肉
    2021-01-04 16:50

    Install getId3 using composer composer require james-heinrich/getid3 Then Use this code to update your id3 tags

    // Initialize getID3 engine
    $getID3 = new getID3;
    
    // Initialize getID3 tag-writing module
    $tagwriter = new getid3_writetags;
    $tagwriter->filename = 'path/to/file.mp3';
    $tagwriter->tagformats = array('id3v2.4');
    $tagwriter->overwrite_tags    = true;
    $tagwriter->remove_other_tags = true;
    $tagwriter->tag_encoding      = 'UTF-8';
    
    $pictureFile = file_get_contents("path/to/image.jpg");
    
    $TagData = array(
        'title' => array('My Title'),
        'artist' => array('My Artist'),
        'album' => array('This Album'),
        'comment' => array('My comment'),
        'year' => array(2018),
        'attached_picture' => array(
            array (
                'data'=> $pictureFile,
                'picturetypeid'=> 3,
                'mime'=> 'image/jpeg',
                'description' => 'My Picture'
            )
        )
    );
    
    $tagwriter->tag_data = $TagData;
    
    // write tags
    if ($tagwriter->WriteTags()){
        return true;
    }else{
        throw new \Exception(implode(' : ', $tagwriter->errors));
    }
    

提交回复
热议问题