getImageDimensions static method

Future<Tuple2<int, int>> getImageDimensions(
  1. String filePath
)

Get Width and Height from file

@param filePath of the media

Implementation

static Future<Tuple2<int, int>> getImageDimensions(String filePath) async {
  try {
    // Open the file
    File file = File(filePath);
    if (!file.existsSync()) {
      return const Tuple2(
          Constants.mobileImageMaxWidth, Constants.mobileImageMaxHeight);
    }

    // Read metadata
    final bytes = await file.readAsBytes();
    final image = await decodeImageFromList(bytes);

    // Get dimensions
    final int width = image.width;
    final int height = image.height;
    // debugPrint('Image dimensions: $width x $height');
    return Tuple2(width, height);
  } catch (e) {
    debugPrint('Error: $e');
    return const Tuple2(
        Constants.mobileImageMaxWidth, Constants.mobileImageMaxHeight);
  }
}