Unverified Commit 86d3bc31 authored by Hong Minhee's avatar Hong Minhee
Browse files

Restore image resizing in `fedify lookup` command

- Replace temporary Sharp removal with proper Jimp-based image processing
- Add support for Ghostty terminal emulator in graphics protocol detection
- Fix image output to stderr to avoid interfering with command output
- Convert images to PNG format for better terminal compatibility

This restores the image resizing functionality that was temporarily removed
in v1.8.2 due to Sharp compatibility issues with deno compile, using the
existing Jimp library that's already available in the codebase.
parent 639d895e
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -8,6 +8,17 @@ Version 1.8.3

To be released.

### @fedify/cli

 -  Restored image resizing functionality in `fedify lookup` command by using
    the existing [Jimp] library for image manipulation. This properly displays
    `icon` and `image` fields with appropriate sizing in terminals.

 -  Added support for Ghostty terminal emulator for image rendering in
    `fedify lookup` command.

[Jimp]: https://jimp-dev.github.io/jimp/


Version 1.8.2
-------------
+15 −6
Original line number Diff line number Diff line
import { encodeBase64 } from "@std/encoding/base64";
import { Jimp } from "./nodeinfo.ts";

export type TerminalType = "kitty" | "iterm2" | "none";

@@ -9,6 +10,7 @@ const KITTY_IDENTIFIERS: string[] = [
  "warp",
  "wayst",
  "st",
  "ghostty",
];

type KittyCommand = Record<string, string | number>;
@@ -76,7 +78,7 @@ export async function renderImageKitty(

    const command = serializeGrCommand(chunkCmd, chunk);

    Deno.stdout.writeSync(command);
    await Deno.stderr.write(command);

    isFirst = false;
  }
@@ -92,7 +94,7 @@ export async function renderImageITerm2(
  const command = encoder.encode(
    `\x1b]1337;File=inline=1preserveAspectRatio=1:${base64Data}\x07\n`,
  );
  Deno.stdout.writeSync(command);
  await Deno.stderr.write(command);
}

export async function downloadImage(url: string): Promise<string | null> {
@@ -118,18 +120,25 @@ export async function renderImages(
    const tempPath = await downloadImage(url.href);
    if (!tempPath) continue;

    console.log(""); // clear the line before rendering image
    const convertedImagePath: `${string}.png` = `${tempPath}.converted.png`;
    const image = await Jimp.read(tempPath);
    await image.write(convertedImagePath);
    await Deno.remove(tempPath);

    console.error(); // clear the line before rendering image

    if (graphicsProtocol === "kitty") {
      await renderImageKitty(tempPath, {
      await renderImageKitty(convertedImagePath, {
        a: "T",
        f: 100, // specify the image format is png
      });
    } else if (graphicsProtocol === "iterm2") {
      await renderImageITerm2(tempPath);
      await renderImageITerm2(convertedImagePath);
    } else {
      continue;
    }
    console.log(""); // clear the line after rendering image
    console.error(); // clear the line after rendering image
  }
}

// cSpell: ignore ghostty iterm konsole magick wezterm wayst