How i get width and height of a image in Laravel Framework?

Viewed 29168

In this image,

image

I can get the width and height of the image in the directory.

But i want to get the width and height of a picture before i upload the image.

How can i achieve this?

6 Answers

Through Intervention Image you can do it as

$upload_file = $request->file('gallery_image');
$height = Image::make($upload_file)->height();
$width = Image::make($upload_file)->width();
[$width, $height] = getimagesize($filename);

run

composer require intervention/image

Then add this to your config/app.php

 return [
       ......
       $providers => [
          ......,
          'Intervention\Image\ImageServiceProvider'
       ],
       $aliases => [
          ......,
          'Image' => 'Intervention\Image\Facades\Image'
       ]
 ];

then use like this.

$upload_file = $request->file('gallery_image');
$height = Image::make($upload_file)->height();
$width = Image::make($upload_file)->width();

If you are using an s3 or some file system other than local, you can use getimagesize($url). The laravel Storage::disk('s3')->url($file_path) can provide what the url, however your s3 must be configured as public. Any url/route to the file will work.

Related