Method 1: Getting Width and Height Using Laravel Intervention
The first method is to use Laravel Intervention package and you can include this package in your project using the composer command below.
composer require intervention/image
<?php // routes/web.php Route::get('image-data', function () { $imageData = \Storage::get('some-image-in-the-storage.jpg'); $width = Image::make($imageData)->width(); // getting the image width $height = Image::make($imageData)->height(); // getting the image height return [ 'width' => $width, 'height' => $height, ]; });
Method 2: Getting Width and Height Using "getimagesize" Method
The second method is to use the "getimagesize()" function available by default from PHP. To use this function you can just call the function and pass in the image resource.
<?php getimagesize($yourImageHere)
<?php // routes/web.php Route::get('image-data', function () { $imageData = \Storage::get('some-image-in-the-storage.jpg'); $width = getimagesize($imageData)[0]; // getting the image width $height = getimagesize($imageData)[1] // getting the image height return [ 'width' => $width, 'height' => $height, ]; });
Leave a reply