Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Deno Image Processor
Deno module for image processing
Features
- Crop
- Resize
- Convert
- Flip
- Rotate
- Apply filter
- Write text
- Join images
To do
- Use
Result<>to return features results.
Accepted extensions
- Png
- Jpeg
- Gif
- WebP
- Pnm
- Tiff
- Tga
- Dds
- Bmp
- Ico
- Hdr
- OpenExr
- Farbfeld
- Avif
Use
Import it
import * as dimg from 'https://deno.land/x/dimg/mod.ts'Data Types
type Rect = {
x: number
y: number
w: number
h: number
}
type Size = {
w: number
h: number
}
type Res = {
status: boolean
err: string
res: Uint8Array
}You probably will never see the
Restype anywhere,
It is the type that Rust returns, but in the Deno code we transform its bad result inthrow new Error(res.err).
(Because of the WebAssembly the types in the pkg folder were made with classes)
Crop image
crop(img: Uint8Array, rect: Rect)
Here’s an example that we open a file and pass its data to crop.
const img = await Deno.readFile(`./image.png`)
dimg.crop(
img,
{
y: 340, x: 328,
h: 100, w: 100
}
)
.then((res: Uint8Array) => {
Deno.writeFile(`./res_image.png`, res)
console.info('Done')
})
.catch((err: Error) => {
console.error(err)
})Resize image
crop(img: Uint8Array, deform: boolean, size: Size)
The same thing as cropping, but this time use the resize function.
And of course see the difference of the parameters type.
The deform parameter is for whether the image should be cut or deformed/redeemed depending on the dimensions.