Skip to content

Commit

Permalink
doc: update deno example
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsinclair committed Jan 7, 2024
1 parent b925337 commit 48d63d3
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions examples/with-deno/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
/**
* To run this example with Deno, run the following command:
* deno run --allow-net --allow-read --allow-write index.js
*
* Note: Requires Deno versions greater than v1.39.0, which introduced the ImageData Web API
*/
import { decode } from 'https://unpkg.com/@jsquash/jpeg@latest?module';
import { encode } from 'https://unpkg.com/@jsquash/webp@latest?module';

// Polyfill ImageData for Deno
// Issue for tracking implementation: https://github.com/denoland/deno/issues/19288
if (typeof ImageData === 'undefined') {
globalThis.ImageData = class ImageData {
constructor(data, width, height) {
this.data = data;
this.width = width;
this.height = height;
}
};
}

const pngBuffer = await Deno.readFile('example.jpg');
const imageData = await decode(pngBuffer);
const jpegBuffer = await Deno.readFile('example.jpg');
const imageData = await decode(jpegBuffer);
const webpBuffer = await encode(imageData);

// Deno writeFile requires a Uint8Array as input
Expand Down

0 comments on commit 48d63d3

Please sign in to comment.