encodeResized static method

String encodeResized(
  1. Image image, {
  2. required int columns,
  3. required int rows,
  4. int cellPixelWidth = 8,
  5. int cellPixelHeight = 16,
  6. int maxColors = maxPaletteSize,
})

Encodes an image with resizing to fit the given cell dimensions.

image is the source image. columns is the target width in terminal columns (each column ≈ 1 pixel width in Sixel, but the caller should account for cell pixel size). rows is the target height in terminal rows. cellPixelWidth is the pixel width of a single terminal cell (default 8). cellPixelHeight is the pixel height of a single terminal cell (default 16). maxColors is the maximum palette size (default 256).

Returns a string containing the complete Sixel escape sequence.

Implementation

static String encodeResized(
  img.Image image, {
  required int columns,
  required int rows,
  int cellPixelWidth = 8,
  int cellPixelHeight = 16,
  int maxColors = maxPaletteSize,
}) {
  final targetWidth = columns * cellPixelWidth;
  // Round target height up to the next multiple of 6 for clean Sixel bands.
  final rawHeight = rows * cellPixelHeight;
  final targetHeight = ((rawHeight + 5) ~/ 6) * 6;

  final resized = img.copyResize(
    image,
    width: targetWidth,
    height: targetHeight,
    interpolation: img.Interpolation.average,
  );

  return encode(resized, maxColors: maxColors);
}