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.