isImage static method

Future<bool> isImage(
  1. MergeInput input
)

Determines whether the given file path corresponds to an image file.

This method uses the file's magic number (file signature) to detect if the file is a PNG, JPEG/JPG or HEIC image, regardless of its extension.

Currently supported image formats:

  • PNG
  • JPEG/JPG
  • HEIC

Parameters:

Returns: true if the file is a PNG or JPEG image, false otherwise (including when an error occurs during detection)

Implementation

static Future<bool> isImage(MergeInput input) async {
  late FileMagicNumberType fileType;
  switch (input.type) {
    case MergeInputType.path:
      fileType =
          await FileMagicNumber.detectFileTypeFromPathOrBlob(input.path!);
      break;
    case MergeInputType.bytes:
      fileType = FileMagicNumber.detectFileTypeFromBytes(input.bytes!);
      break;
  }
  return fileType == FileMagicNumberType.png ||
      fileType == FileMagicNumberType.jpg ||
      fileType == FileMagicNumberType.heic;
}