// 生成 1014×642 测试卡 PNG(真实打印验收用),默认输出 build/test_card.png // dart run tool/make_test_card.dart [输出路径] import 'dart:io'; import 'package:image/image.dart'; Future main(List args) async { final img = Image(width: 1014, height: 642); fill(img, color: ColorRgb8(255, 255, 255)); // 边框 drawRect(img, x1: 8, y1: 8, x2: 1005, y2: 633, color: ColorRgb8(0, 120, 215)); // CMYK 色块:验证四色分色与套印 fillRect(img, x1: 60, y1: 60, x2: 300, y2: 300, color: ColorRgb8(0, 174, 239)); fillRect(img, x1: 320, y1: 60, x2: 560, y2: 300, color: ColorRgb8(236, 0, 140)); fillRect(img, x1: 580, y1: 60, x2: 820, y2: 300, color: ColorRgb8(255, 221, 0)); fillRect(img, x1: 840, y1: 60, x2: 960, y2: 300, color: ColorRgb8(0, 0, 0)); drawString(img, 'DESKTOP-PLUGIN TEST CARD', font: arial24, x: 60, y: 360, color: ColorRgb8(20, 20, 20)); drawString( img, 'flutter print verify ${DateTime.now().toIso8601String().substring(0, 19)}', font: arial14, x: 60, y: 420, color: ColorRgb8(90, 90, 90), ); drawString(img, '127.0.0.1:38200 /api/card-printer/print', font: arial14, x: 60, y: 450, color: ColorRgb8(90, 90, 90)); final png = encodePng(img); final out = args.isNotEmpty ? args.first : 'build/test_card.png'; final file = File(out); await file.parent.create(recursive: true); await file.writeAsBytes(png); // ignore: avoid_print print('written $out (${png.length} bytes)'); }