Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fakoua/jpeg.ts

A pure TypeScript JPEG encoder and decoder for deno
https://github.com/fakoua/jpeg.ts

decoding deno encoding image jpeg

Last synced: 1 day ago
JSON representation

A pure TypeScript JPEG encoder and decoder for deno

Awesome Lists containing this project

README

        

# jpeg.ts

A pure TypeScript JPEG encoder and decoder for deno

![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/fakoua/jpeg.ts?style=for-the-badge)
![GitHub](https://img.shields.io/github/license/fakoua/jpeg.ts?style=for-the-badge)
![GitHub last commit](https://img.shields.io/github/last-commit/fakoua/jpeg.ts?style=for-the-badge)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/fakoua/jpeg.ts/Deno%20CI?style=for-the-badge)
## decoder

```ts
import { decode } from "https://deno.land/x/jpeg.ts/mod.ts"

//read image data:
let raw = await Deno.readFile(fullPath)
//decode"
let result = decode(raw);

//result.width: Image width
//result.height: Image height

//result.data[0] -> Red
//result.data[1] -> Green
//result.data[2] -> Blue
//result.data[3] -> Alpha
//...

// result.data is an array of RGBa colors
```

Also you can access the pixel of the image:

```ts
import { decode } from "https://deno.land/x/jpeg.ts/mod.ts"

//read image data:
let raw = await Deno.readFile(fullPath)
//decode"
let result = decode(raw);

let pix = result.getPixel(12, 33); // -> { r: 0, g: 0, b: 254, a: 255 }
// result.getPixel(x, y)
//while 0 <= x < result.width and 0 <= y < result.height
```

## encoder

```ts
import { encode, Image } from "https://deno.land/x/jpeg.ts/mod.ts"

// make image with red gree blue and alpha colors

let image: Image = {
width: 2,
height: 2,
data: new Uint8Array( [
255,0,0,1,
0,255,0,1,
0,0,255,1,
255,255,0,1,
])
}

let raw = encode(image, 100); //Quality 100 (default is 50)
//save the image
await Deno.writeFile('rgb.jpg', raw.data);
```