decodeImageFile function

Future<Image> decodeImageFile(
  1. String filePath
)

Decodes an image file at filePath.

Throws NoDecoderForImageFormatException if the file's format is not recognized by package:image. SVG sources raise an InvalidConfigException with a clear "not yet supported" message (upstream #020) — full SVG rasterization is a future feature gated on a vector renderer dependency.

Implementation

Future<Image> decodeImageFile(String filePath) async {
  if (filePath.toLowerCase().endsWith('.svg')) {
    throw InvalidConfigException(
      "'$filePath' is an SVG. SVG sources are not yet supported; please "
      'convert to PNG. Tracked as upstream #020.',
    );
  }
  final image = decodeImage(await File(filePath).readAsBytes());
  if (image == null) {
    throw NoDecoderForImageFormatException(filePath);
  }
  return image;
}