rotate method

Future<File> rotate(
  1. XFile file,
  2. String path
)

Implementation

Future<File> rotate(XFile file, String path) async {
  final File imageFile = File(file.path);
  final List<int> imageBytes = await imageFile.readAsBytes();

  img.Image? image = img.decodeImage(Uint8List.fromList(imageBytes));

  jLog.d(
    "${image!.width} * ${image.height} , Size: ${(await imageFile.length() ~/ 1024)} KB",
  );

  if (image.width > image.height) image = img.copyRotate(image, angle: 90);

  final w = image.width;
  final h = image.height ~/ 2.7;
  final x = 0;
  final y = (image.height - h) ~/ 2;

  image = img.copyCrop(image, x: x, y: y, width: w, height: h);

  final out = File(path)..writeAsBytesSync(img.encodeJpg(image, quality: 40));

  jLog.d(
    "${image.width} * ${image.height} , Size: ${(await out.length() ~/ 1024)} KB",
  );

  return out;
}