Skip to content

Commit

Permalink
feat: add option to export Uint8Array for the hash
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaudiuCeia committed Nov 9, 2022
1 parent fde2239 commit ccce9a8
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/dhash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const toAscii = (hash: string, chars = ["░░", "██"]) => {
return row + chars[0];
};

export const save = async (hash: string, file: string) => {
export const raw = async (hash: string): Promise<Uint8Array> => {
const bin = parseInt(hash, 16).toString(2).split("");
const out = new Image(8, 8);

Expand All @@ -91,6 +91,10 @@ export const save = async (hash: string, file: string) => {
}

out.setPixelAt(8, 8, white);
const enc = await out.encode();
return await out.encode();
};

export const save = async (hash: string, file: string): Promise<void> => {
const enc = await raw(hash);
await Deno.writeFile(`${file}.png`, enc);
};

0 comments on commit ccce9a8

Please sign in to comment.