
























@@ -1,7 +1,19 @@
1+import { spawnSync } from "node:child_process";
2+import fs from "node:fs/promises";
3+import os from "node:os";
4+import path from "node:path";
15import { describe, expect, it } from "vitest";
2-import { getImageMetadata, MAX_IMAGE_INPUT_PIXELS, resizeToJpeg } from "./image-ops.js";
6+import {
7+convertHeicToJpeg,
8+getImageMetadata,
9+MAX_IMAGE_INPUT_PIXELS,
10+resizeToJpeg,
11+} from "./image-ops.js";
312import { createPngBufferWithDimensions } from "./test-helpers.js";
41314+const PNG_1X1_BASE64 =
15+"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADUlEQVR4nGP8z8BQDwAFgwJ/lH3vWQAAAABJRU5ErkJggg==";
16+517describe("image input pixel guard", () => {
618const oversizedPng = createPngBufferWithDimensions({ width: 8_000, height: 4_000 });
719const overflowedPng = createPngBufferWithDimensions({
@@ -53,4 +65,30 @@ describe("image input pixel guard", () => {
5365}
5466}
5567});
68+69+const itIfMac = process.platform === "darwin" ? it : it.skip;
70+71+itIfMac("converts macOS-generated HEIC images to JPEG", async () => {
72+const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-heic-convert-"));
73+try {
74+const pngPath = path.join(tempDir, "input.png");
75+const heicPath = path.join(tempDir, "input.heic");
76+await fs.writeFile(pngPath, Buffer.from(PNG_1X1_BASE64, "base64"));
77+const result = spawnSync(
78+"/usr/bin/sips",
79+["-s", "format", "heic", pngPath, "--out", heicPath],
80+{
81+encoding: "utf8",
82+},
83+);
84+expect(result.status, result.stderr || result.stdout).toBe(0);
85+86+const jpeg = await convertHeicToJpeg(await fs.readFile(heicPath));
87+88+expect(jpeg[0]).toBe(0xff);
89+expect(jpeg[1]).toBe(0xd8);
90+} finally {
91+await fs.rm(tempDir, { force: true, recursive: true });
92+}
93+});
5694});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。