createStickerFromImage method
Creates valid sticker from image at imagePath and saves it to
stickerPath
Resizes and compresses image if necessary
Implementation
Future<String> createStickerFromImage(
String imagePath,
String stickerPath,
) async {
if (!stickerPath.endsWith('.webp')) stickerPath += '.webp';
_validateImage(imagePath);
// If is animated webp: validate and return without sizing/compressing
if (isStickerAnimated(imagePath)) {
return await _handleAnimatedSticker(imagePath, stickerPath);
}
// Resize to 512x512
Image? scaledImage = await _fileService.scaleImageToSquare(imagePath, 512);
// Compress to max 95KB
Uint8List bytes = await _fileService.compressFileTo(
encodePng(scaledImage!),
95000,
CompressFormat.webp,
);
return await _fileService.saveBytesToFile(bytes, stickerPath);
}