Search code examples
laravellaravel-medialibrary

How in spatie/laravel-medialibrary get dimensions of uploaded image?


Using spatie/laravel-medialibrary 8 in Laravel 8 app I wonder if there is a way to get dimensions(width*height) of uploaded image?

Thanks in advance!


Solution

  • I haven't tested the code.

    Spatie MediaLibrary uses spatie Image package behind the scenes to generate responsive Images.

    Since the image package has a option to get the Image Properties

    So you can do Something like this.

    $fullPathToImage = 'your-path-here';
    
    $imageInstance = Spatie\MediaLibrary\Support\ImageFactory::load($fullPathToImage);
    
    
    $imageWidth = $imageInstance->getWidth();
    $imageHeight = $imageInstance->getHeight();
    

    since I have't tested the code. But it will provide you some sort of starting point to solve the issue.