Skip to content

Instantly share code, notes, and snippets.

@zettca
Created January 11, 2023 16:32
Show Gist options
  • Save zettca/1935b9b6e8b7f7c5142ad1dacb5d51e3 to your computer and use it in GitHub Desktop.
Save zettca/1935b9b6e8b7f7c5142ad1dacb5d51e3 to your computer and use it in GitHub Desktop.
`jimp` vs `photon`
import Jimp from "npm:jimp";
const fileName = Deno.args[0];
console.time("time");
console.time("init");
const img = await Jimp.read(fileName);
console.timeEnd("init");
console.time("work");
img
.resize(256, 256) // resize
.quality(60) // set JPEG quality
.greyscale(); // set greyscale
console.timeEnd("work");
console.timeEnd("time");
import photon from "npm:@silvia-odwyer/photon-node";
import { encode } from "https://deno.land/std@0.171.0/encoding/base64.ts";
const fileName = Deno.args[0];
console.time("time");
console.time("readFile");
const data = await Deno.readFile(fileName);
console.timeEnd("readFile");
console.time("digest");
const hashBytes = await crypto.subtle.digest("SHA-1", data);
const toHex = (b: number) => b.toString(16).padStart(2, "0");
Array.from(new Uint8Array(hashBytes), toHex).join("");
`${Math.round(data.length / 2 ** 20)}MB`;
console.timeEnd("digest");
console.time("encoding");
const b64Data = encode(data);
console.timeEnd("encoding");
console.time("new");
const img = photon.PhotonImage.new_from_base64(b64Data);
console.timeEnd("new");
console.time("work");
photon.resize(img, 200, 200, 1);
photon.grayscale(img);
console.timeEnd("work");
console.timeEnd("time");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment