snapshot of https://github.com/flutter/samples.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled
Some checks failed
Main Branch CI / Test Flutter beta on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter stable on ubuntu-latest (push) Has been skipped
Main Branch CI / Test Flutter beta on macos-latest (push) Has been cancelled
Main Branch CI / Test Flutter stable on macos-latest (push) Has been cancelled
This commit is contained in:
3
asset_transformation/grayscale_transformer/.gitignore
vendored
Normal file
3
asset_transformation/grayscale_transformer/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
# https://dart.dev/guides/libraries/private-files
|
||||
# Created by `dart pub`
|
||||
.dart_tool/
|
||||
3
asset_transformation/grayscale_transformer/CHANGELOG.md
Normal file
3
asset_transformation/grayscale_transformer/CHANGELOG.md
Normal file
@@ -0,0 +1,3 @@
|
||||
## 1.0.0
|
||||
|
||||
- Initial version.
|
||||
@@ -0,0 +1,10 @@
|
||||
analyzer:
|
||||
exclude:
|
||||
- build/**
|
||||
- android/**
|
||||
- ios/**
|
||||
- web/**
|
||||
- windows/**
|
||||
- macos/**
|
||||
- linux/**
|
||||
include: ../../analysis_options.yaml
|
||||
@@ -0,0 +1,38 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/args.dart';
|
||||
import 'package:image/image.dart';
|
||||
|
||||
const inputOptionName = 'input';
|
||||
const outputOptionName = 'output';
|
||||
|
||||
int main(List<String> arguments) {
|
||||
// The flutter tool will invoke this program with two arguments, one for
|
||||
// the `--input` option and one for the `--output` option.
|
||||
// `--input` is the original asset file that this program should transform.
|
||||
// `--output` is where flutter expects the transformation output to be written to.
|
||||
final parser = ArgParser()
|
||||
..addOption(inputOptionName, mandatory: true, abbr: 'i')
|
||||
..addOption(outputOptionName, mandatory: true, abbr: 'o');
|
||||
|
||||
ArgResults argResults = parser.parse(arguments);
|
||||
final String inputFilePath = argResults[inputOptionName] as String;
|
||||
final String outputFilePath = argResults[outputOptionName] as String;
|
||||
|
||||
try {
|
||||
final Image image = decodeImage(File(inputFilePath).readAsBytesSync())!;
|
||||
final Image imageInGrayscale = grayscale(image);
|
||||
File(outputFilePath).writeAsBytesSync(encodeJpg(imageInGrayscale));
|
||||
|
||||
return 0;
|
||||
} catch (e) {
|
||||
// The flutter command line tool will see a non-zero exit code (1 in this case)
|
||||
// and fail the build. Anything written to stderr by the asset transformer
|
||||
// will be surfaced by flutter.
|
||||
stderr.writeln(
|
||||
'Unexpected exception when producing grayscale image.\n'
|
||||
'Details: $e',
|
||||
);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
15
asset_transformation/grayscale_transformer/pubspec.yaml
Normal file
15
asset_transformation/grayscale_transformer/pubspec.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
name: grayscale_transformer
|
||||
description: A sample command-line application.
|
||||
version: 1.0.0
|
||||
resolution: workspace
|
||||
|
||||
environment:
|
||||
sdk: ^3.9.0-0
|
||||
|
||||
dependencies:
|
||||
args: ^2.4.2
|
||||
image: ^4.1.7
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^6.0.0
|
||||
test: ^1.24.0
|
||||
Reference in New Issue
Block a user