Skip to main content
Deno 2 is finally here 🎉️
Learn more

Deno Image Processor

Deno module for image processing Picture twemoji Sauropod


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'

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

resize(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/resized depending on the dimensions.

Flip image

flip(img: Uint8Array, dir: Direction)

The Direction type definition:

export enum Direction {
  Horizontal,
  Vertical
}

Rotate image

rotate(img: Uint8Array, deg: number)

The deg parameter expects the number of degrees you want to rotate the image.
(i.e.: from 0 to 360)