replace_palette 0.1.4 replace_palette: ^0.1.4 copied to clipboard
Replaces the color palette in an image, respecting the color models. The easy-to-use and well-tested package.
// ignore_for_file: avoid_print
import 'dart:io';
import 'package:image/image.dart';
import 'package:replace_palette/replace_palette.dart';
import 'package:uni_color_name/uni_color_name.dart';
/// Run:
/// ```
/// cd example
/// dart main.dart
/// ```
Future<void> main() async {
const fileSource = 'colorful_swirl';
const filesPalettes = ['black_white', 'faber_castell_36'];
for (final fp in filesPalettes) {
await dress(fileSource, fp);
}
print('✅ Files created in the `example` folder.');
}
Future<void> dress(String fileSource, String filePalette) async {
final palette = UniPalette<int>.file(
'palettes/$filePalette.json',
ColorModel.rgb,
);
final image =
await const Dresser().dressFile(File('data/$fileSource.webp'), palette);
File('../_output/${fileSource}_$filePalette.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
}
Future<void> dressExample() async {
final palette = UniPalette<int>.file('my_palette.json', ColorModel.rgb);
final image = await const Dresser().dressFile(File('my_image.webp'), palette);
File('my_result.png')
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
}