Dart Image Library for opening, manipulating, and saving various different image file formats.
翻译准备中
开发工具Dart · CSSGitHub @brendan-duncan自行安装运营者未确认
试用过了吗? 点一下就好,无需登录。
尚未检测到更新。GitHub 发布版本后会显示在这里。
个人 GitHub 账号下公开仓库的所有者可以登录并验证所有权,自行管理介绍,无需管理员批准。
登录并生成验证文件,在 30 分钟内将其提交到此仓库的默认分支。其他分支或分叉仓库中的文件无效。然后在下方检查文件,即可无需管理员批准直接管理项目。请保留文件以维持管理权限。
如需登录,将前往登录页面。登录后请回到此处,再次点击所选的验证按钮。
安装型项目无需部署域名也可验证。个人仓库可通过 GitHub 登录验证,组织仓库可使用上方的仓库验证文件。
制作者的介绍仅有上面的一句话。 更多详情请阅读仓库 README。 仓库 README ↗
正在加载完整 README。
查看完整 README ↗The Dart Image Library loads, saves and manipulates images in a variety of image file formats.
It's written in pure Dart with no native dependencies, so it works everywhere Dart does: command-line apps, servers, Flutter on every platform, and the web.
Features include:
Read/Write
Read Only
Write Only
dart pub add image
import 'package:image/image.dart' as img;
Create an image, set pixel values, and save it as a PNG:
import 'dart:io';
import 'package:image/image.dart' as img;
Future<void> main() async {
// Create a 256x256 8-bit (default) RGB (default) image.
final image = img.Image(width: 256, height: 256);
// Iterate over its pixels.
for (final pixel in image) {
pixel
// Set the red channel to the x position, creating a gradient.
..r = pixel.x
// Set the green channel to the y position.
..g = pixel.y;
}
// Encode the image to the PNG format.
final png = img.encodePng(image);
// Write the PNG data to a file.
await File('image.png').writeAsBytes(png);
}
Load a JPEG, make a thumbnail, and save it:
import 'dart:io';
import 'package:image/image.dart' as img;
Future<void> main() async {
final bytes = await File('photo.jpg').readAsBytes();
// Decode the JPEG. This returns null, or throws an ImageException, if the
// data isn't a valid JPEG.
final image = img.decodeJpg(bytes);
if (image == null) {
return;
}
// Resize to 120 pixels wide, keeping the aspect ratio. The EXIF orientation
// of the photo is applied.
final thumbnail = img.copyResize(image, width: 120);
// Encode as a JPEG and save it.
await File('thumbnail.jpg').writeAsBytes(img.encodeJpg(thumbnail, quality: 85));
}
Do the same work in a separate isolate with the Command API, so it doesn't block the main isolate:
import 'package:image/image.dart' as img;
Future<void> main(List<String> args) async {
final path = args.isNotEmpty ? args[0] : 'test.png';
final cmd = img.Command()
// Decode the image file at the given path.
..decodeImageFile(path)
// Resize the image to a width of 64 pixels, keeping the aspect ratio.
..copyResize(width: 64)
// Write the image to a PNG file (the format comes from the file extension).
..writeToFile('thumbnail.png');
// On platforms that support isolates, execute the commands on a separate
// isolate. Otherwise (on the web), they run on the main thread.
await cmd.executeThread();
}
See the tutorial for more.