How to detect if an image is vertical or horizontal

679

Solution 1

decodeImageFromList() provides us the height and width of the image, based on the size we can decide whether the given image is vertical or horizontal.

    import 'dart:io';

    final picker = ImagePicker();
    final pickedFile = await picker.getImage(source: ImageSource.camera);

    File image = new File(pickedFile.path); 
    var decodedImage = await decodeImageFromList(image.readAsBytesSync());
    bool isHorizontalImage = decodedImage.width > decodedImage.height;

Solution 2

Once you get the file from picker, convert to Image and get the width & height, calculate the ratio then you get the orientation:

image = Image.memory(await pickedFile.readAsBytes())
Share:
679
Adrián Casabuena Saez
Author by

Adrián Casabuena Saez

Updated on December 29, 2022

Comments

  • Adrián Casabuena Saez
    Adrián Casabuena Saez over 1 year

    I am making an App in Flutter in which I use image_picker and I would like to know how to know the orientation of an image, if an image is vertical or horizontal.

    Is there any way to do it?

  • GOBINATH.M
    GOBINATH.M almost 3 years
    bool isLandscapeImage = image.width > image.height;