toJpegQ80 function
Matches TelegramRobust2Steganography.toJpegQ80 on Android/iOS.
Implementation
Uint8List? toJpegQ80(Uint8List imageBytes) {
final decoded = img.decodeImage(imageBytes);
if (decoded == null) return null;
var image = decoded;
final maxSide = max(image.width, image.height);
if (maxSide > 1280) {
final scale = 1280 / maxSide;
final nw = max((image.width * scale).round(), 8);
final nh = max((image.height * scale).round(), 8);
image = img.copyResize(image, width: nw, height: nh);
}
return Uint8List.fromList(img.encodeJpg(image, quality: 80));
}