Created
January 11, 2023 16:32
-
-
Save zettca/1935b9b6e8b7f7c5142ad1dacb5d51e3 to your computer and use it in GitHub Desktop.
`jimp` vs `photon`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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