3

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?

Zayn Ali
  • 4,425
  • 1
  • 27
  • 39
ThomasPham
  • 69
  • 1
  • 1
  • 3

6 Answers6

26
 $data = getimagesize($filename);
 $width = $data[0];
 $height = $data[1];
Kuldeep Mishra
  • 3,395
  • 1
  • 18
  • 25
9

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();
Daud khan
  • 2,045
  • 2
  • 12
  • 15
2
[$width, $height] = getimagesize($filename);
Arash Younesi
  • 1,373
  • 1
  • 10
  • 21
1

You can use

 <?php
$imagedetails = getimagesize($_FILES['file-vi']['tmp_name']);

$width = $imagedetails[0];
$height = $imagedetails[1];

?>
Aan Faisal
  • 31
  • 1
  • 7
1

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();
Benjamin
  • 55
  • 6
0

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.

Tarek Adam
  • 2,923
  • 3
  • 22
  • 46