PHP code example of owen-oj / laravel-getid3

1. Go to this page and download the library: Download owen-oj/laravel-getid3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

owen-oj / laravel-getid3 example snippets


use Owenoj\LaravelGetId3\GetId3;
use Illuminate\Support\Facades\Storage

// From an uploaded file (e.g. from a form request)
$track = GetId3::fromUploadedFile(request()->file('file'));

// From a Laravel storage disk (works with local, S3, etc.)
$track = GetId3::fromDiskAndPath('local', '/some/file.mp3');
$track = GetId3::fromDiskAndPath('s3', 'uploads/video.mp4');
$track = GetId3::fromDiskAndPath(Storage::disk('public'), 'uploads/video.mp4');

// Direct constructor with a file path
$track = new GetId3('/absolute/path/to/file.flac');

// Raw array of everything getID3 can extract
$track->extractInfo();

// Common audio tags
$track->getTitle();          // "Bohemian Rhapsody"
$track->getArtist();         // "Queen"
$track->getAlbum();          // "A Night at the Opera"
$track->getYear();           // "1975"
$track->getPlaytime();       // "5:55"
$track->getPlaytimeSeconds(); // 354.63

// Common video info
$track->getVideoWidth();     // 1920
$track->getVideoHeight();    // 1080
$track->getVideoAspectRatio(); // "16:9"
$track->getFrameRate();      // 29.97
$track->getVideoCodec();     // "h264"

// Check what kind of media it is
$track->isAudio();  // true / false
$track->isVideo();  // true / false

// Base64 string — embed directly in an <img> src
$base64 = $track->getArtwork();

// UploadedFile JPEG — move it anywhere Laravel's Storage accepts
$jpeg = $track->getArtwork(true);
Storage::disk('public')->put('covers/'.$jpeg->getFilename(), file_get_contents($jpeg->getPathname()));

// Raw binary — pass straight to an image library
$binary = $track->getArtworkData();
$mime   = $track->getArtworkMimeType(); // "image/png"

$track = GetId3::fromDiskAndPath('local', 'music/track.flac');

echo $track->getAudioCodec();    // "flac"
echo $track->getSampleRate();    // 96000
echo $track->getBitsPerSample(); // 24
echo $track->isLossless()
    ? 'Lossless'
    : 'Lossy';                   // "Lossless"

$video = GetId3::fromUploadedFile(request()->file('video'));

if ($video->isVideo()) {
    ['width' => $w, 'height' => $h] = $video->getVideoDimensions();
    echo "{$w}x{$h} @ {$video->getFrameRate()} fps"; // "1920x1080 @ 29.97 fps"
    echo $video->getVideoAspectRatio();               // "16:9"
    echo $video->getVideoCodec();                     // "h264"

    // Handle portrait video from a phone
    if ($video->getVideoRotation() === 90) {
        // swap width/height for display
    }
}