Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,22 @@ jobs:
working-directory: ./examples/mean-squares-versor-registration/typescript
run: |
pnpm build

test-deno-example:
name: deno
runs-on: ubuntu-24.04

defaults:
run:
working-directory: ./examples/deno

steps:
- uses: actions/checkout@v4

- uses: denoland/setup-deno@v1
with:
deno-version: v2.x

- name: Test
run: |
deno task test
65 changes: 65 additions & 0 deletions docs/typescript/distribution/deno.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# ITK-Wasm in a Deno application

An `itk-convert` command line interface (CLI) example demonstrates how to use ITK-Wasm in a Deno application. Find the full example in the `ITK-Wasm/examples/deno` [directory of the GitHub repository](https://github.com/InsightSoftwareConsortium/ITK-Wasm/tree/main/examples/deno).

This example assumes you are creating a [Deno project](https://docs.deno.com/runtime/fundamentals/configuration/). If you do not already have a `deno.json` file, [create one](https://docs.deno.com/runtime/fundamentals/configuration/) first.

Add packages to your project's imports:

```json
{
"imports": {
"@itk-wasm/image-io": "npm:@itk-wasm/image-io",
"@itk-wasm/mesh-io": "npm:@itk-wasm/mesh-io",
"itk-wasm": "npm:itk-wasm"
}
}
```

This adds `itk-wasm` and ITK-Wasm IO packages to the `imports` section of your *deno.json* file:

```json
{
"name": "itk-convert",
"version": "1.0.0",
"description": "Convert image or mesh files from one format to another.",
"exports": "./src/itk-convert.ts",
"tasks": {
"test": "deno run --allow-read --allow-write src/itk-convert.ts ../../docs/_static/logo.png ./logo.tif"
},
"imports": {
"@itk-wasm/image-io": "npm:@itk-wasm/image-io",
"@itk-wasm/mesh-io": "npm:@itk-wasm/mesh-io",
"itk-wasm": "npm:itk-wasm@1.0.0-b.188"
},
"compilerOptions": {
"strict": true
}
}
```

Next, call functions like [`readImageNode`](https://itk-wasm-image-io-docs-js.on.fleek.co/#/?id=readimagenode) or [`writeImageNode`](https://itk-wasm-image-io-docs-js.on.fleek.co/#/?id=writeimagenode).

For example,

```typescript
import { readImageNode, writeImageNode } from '@itk-wasm/image-io'
import { readMeshNode, writeMeshNode, extensionToMeshIo } from '@itk-wasm/mesh-io'
import { getFileExtension } from 'itk-wasm'

const extension = getFileExtension(inputFile).toLowerCase()
const isMesh = extensionToMeshIo.has(extension)

try {
if (isMesh) {
const mesh = await readMeshNode(inputFile)
await writeMeshNode(mesh, outputFile)
} else {
const image = await readImageNode(inputFile)
await writeImageNode(image, outputFile)
}
} catch (error) {
console.error('Error during conversion:\n')
console.error(error)
}
```
1 change: 1 addition & 0 deletions docs/typescript/distribution/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ esm.md
vite.md
webpack.md
node.md
deno.md
```
1 change: 1 addition & 0 deletions examples/deno/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logo.tif
33 changes: 33 additions & 0 deletions examples/deno/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
itk-convert
===========

Convert an image or mesh from one file format to another.

This example [deno](https://docs.deno.com) package provides a command line executable, `itk-convert` to convert
image file formats with
[ITK-Wasm](https://github.com/InsightSoftwareConsortium/ITK-Wasm.git).

## Installation

```
deno install
```

## Usage

```
deno src/itk-convert.ts <inputFile> <outputFile>
```

## Development

```
deno task test
```

## More Information

This example demonstrates how to use
[ITK-Wasm](https://wasm.itk.org/) in a Node.js
application. More information can be found in the [example
documentation](https://docs.itk.org/projects/wasm/en/latest/typescript/distribution/deno.html).
17 changes: 17 additions & 0 deletions examples/deno/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "itk-convert",
"version": "1.0.0",
"description": "Convert image or mesh files from one format to another.",
"exports": "./src/itk-convert.ts",
"tasks": {
"test": "deno run --allow-read --allow-write src/itk-convert.ts ../../docs/_static/logo.png ./logo.tif"
},
"imports": {
"@itk-wasm/image-io": "npm:@itk-wasm/image-io",
"@itk-wasm/mesh-io": "npm:@itk-wasm/mesh-io",
"itk-wasm": "npm:itk-wasm@1.0.0-b.188"
},
"compilerOptions": {
"strict": true
}
}
Loading
Loading