createBackgroundImage function

void createBackgroundImage({
  1. required String imageDestination,
  2. required String imageSource,
})

Implementation

void createBackgroundImage({
  required String imageDestination,
  required String imageSource,
}) {
  // Copy will not work if the directory does not exist, so createSync
  // will ensure that the directory exists.
  File(imageDestination).createSync(recursive: true);

  // If source image is not already png, convert it, otherwise just copy it.
  if (p.extension(imageSource).toLowerCase() != '.png') {
    final image = decodeImage(File(imageSource).readAsBytesSync());
    if (image == null) {
      print('$imageSource could not be read');
      exit(1);
    }
    File(imageDestination)
      ..createSync(recursive: true)
      ..writeAsBytesSync(encodePng(image));
  } else {
    File(imageSource).copySync(imageDestination);
  }
}