Laravel is rotating the image when uploaded

前端 未结 2 1240
暗喜
暗喜 2021-01-04 19:59

I am developing a web application that involves the feature of uploading image to server. I am using Laravel. The problem is when I upload a photo, Laravel is rotating the i

相关标签:
2条回答
  • 2021-01-04 20:18

    This happen when you capture the image with Mobile camera.

    you can see the image data using exif_read_data()

    But if you want to store it in an orignal way you can use intervention/image package.

    and use orientate() to change it. Here is an example

    $img = \Image::make($request->file('image_file')->getRealpath());
    $img->orientate();
    

    But if you dont want to use the Package you can try

    $exif = exif_read_data($request->file('image_file'));
    if(!empty($exif['Orientation'])) {
        switch($exif['Orientation']) {
            case 8:
                $image = imagerotate($image,90,0);
                break;
            case 3:
                $image = imagerotate($image,180,0);
                break;
            case 6:
                $image = imagerotate($image,-90,0);
                break;
        }
    }
    

    Hope this helps.

    0 讨论(0)
  • 2021-01-04 20:25

    i found an easy way to do it its work for me you just upload your image in google drive then download it again that s it if it doesnt work i m sorry but it s work for me

    0 讨论(0)
提交回复
热议问题