MIT License

项目介绍

brendan-duncan/image 是一个托管在 GitHub 上的开源项目,主要使用 Dart 编写,采用 MIT License 许可证,目前获得 1.3k 个 Star、302 次 Fork。

仓库全名
brendan-duncan/image
开源许可证
MIT License
Star 数
1.3k
Fork 数
302
未关闭 Issue
55

README 摘要

Dart Image Library Overview 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: Decoding and encoding many image formats, including animated GIF, PNG and WebP. Resizing, cropping, rotating and…

完整内容见 GitHub 原始 README 或本页 。

常见问题

image 用什么语言开发?

主要使用 Dart 编写,采用 MIT License 许可证,目前有 1.3k 个 Star。

image 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 image 的源码?

可以直接克隆仓库:git clone https://github.com/brendan-duncan/image.git,默认分支为 main;安装与运行步骤见仓库 README。

image 最近还在维护吗?

仓库最近一次更新为 1 周前,当前有 55 个未关闭 Issue;Star 数为 1.3k,可作为社区活跃度的参考。

README

Dart Image Library

Dart CI pub package

Overview

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:

Documentation

Supported Image Formats

Read/Write

  • JPEG
  • PNG / Animated PNG
  • GIF / Animated GIF
  • WebP / Animated WebP (lossless and lossy)
  • BMP
  • TIFF
  • TGA
  • ICO
  • PVR

Read Only

  • PSD
  • EXR
  • PNM (PBM, PGM, PPM)

Write Only

  • CUR

Getting started

dart pub add image
import 'package:image/image.dart' as img;

Examples

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.

评论

暂无评论