Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Storage::get() does not return exif data of image

Tags:

php

image

laravel

I am trying to get the image exif data so that I can use the Image intervention orientate function.

The only problem is that I cant read the exif data using the Storage::get()

First I am storing Uploaded images like this:

$filename = uniqid().'.'.$file->getClientOriginalExtension();
$path = "images/$id/$filename";
Storage::put($path, File::get($file->getRealPath()));

The in a queue I am reading the images, doing some resizing and upload to AWS:

$image = Image::make(Storage::disk('images')->get("$this->id/$file"));
            $image->orientate();
            $image->resize(null, 600, function ($constraint) {
                $constraint->aspectRatio();
            });
            $image->stream('jpg', 85);
Storage::put("images/$this->id/main/$file", $image);
$image->destroy();

The image does get resized and uploaded to AWS but the only problem is that it will show up sideways, so it seems that I cant read the exif data using:

Storage::disk('images')->get("$this->id/$file")

I have runned: php -m | more and I can see that "exif" is listed so I have the module in my Laravel Forge DO server

like image 940
user2722667 Avatar asked Nov 18 '16 21:11

user2722667


1 Answers

Install Intervention\Image by following command.

composer require intervention/image

Update config/app.php

'providers' => [
    Intervention\Image\ImageServiceProvider::class
],
'aliases' => [
    'Image' => Intervention\Image\Facades\Image::class
]

Use Library:

$data = Image::make(public_path('IMG.jpg'))->exif();

if (isset($data['GPSLatitude'])) {
    $lat = eval('return ' . $data['GPSLatitude'][0] . ';')
        + (eval('return ' . $data['GPSLatitude'][1] . ';') / 60)
        + (eval('return ' . $data['GPSLatitude'][2] . ';') / 3600);

    $lng = eval('return ' . $data['GPSLongitude'][0] . ';')
        + (eval('return ' . $data['GPSLongitude'][1] . ';') / 60)
        + (eval('return ' . $data['GPSLongitude'][2] . ';') / 3600);

    echo "$lat, $lng";
} else {
    echo "No GPS Info";
}
like image 132
Web Developer in Pune Avatar answered Oct 08 '22 11:10

Web Developer in Pune