|
| 1 | +--- |
| 2 | +title: Getting started |
| 3 | +sidebar_position: 0 |
| 4 | +--- |
| 5 | + |
| 6 | +import Tabs from '@theme/Tabs'; |
| 7 | +import TabItem from '@theme/TabItem'; |
| 8 | + |
| 9 | +# Getting started |
| 10 | + |
| 11 | +ImageJS is a versatile and powerful library written in TypeScript for image processing and analysis. It gives a user a comprehensive set of tools and algorithms for manipulating, enhancing, and understanding images not only within Node.js but also across all popular browsers. |
| 12 | + |
| 13 | +## System requirements |
| 14 | + |
| 15 | +ImageJS is a modern library and does not actively support outdated runtimes. |
| 16 | +One of the following is required: |
| 17 | + |
| 18 | +- An officially supported version of [Node.js](https://nodejs.org/en/download). |
| 19 | +- A modern and up-to-date web browser. |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +Installation of ImageJS is straight-forward. Use the terminal to install the package: |
| 24 | + |
| 25 | +<Tabs> |
| 26 | +<TabItem value="npm" label="npm" default> |
| 27 | + |
| 28 | +``` |
| 29 | +npm install image-js |
| 30 | +``` |
| 31 | + |
| 32 | +</TabItem> |
| 33 | +<TabItem value="yarn" label="yarn"> |
| 34 | + |
| 35 | +``` |
| 36 | +yarn add image-js |
| 37 | +``` |
| 38 | + |
| 39 | +</TabItem> |
| 40 | +</Tabs> |
| 41 | + |
| 42 | +## Loading your first image |
| 43 | + |
| 44 | +There are two ways of loading an image to process it, depending on the way the user is operating: |
| 45 | + |
| 46 | +### Loading and saving an image from Node.js |
| 47 | + |
| 48 | +Local loading uses the `readSync` or `read` function with a filepath: |
| 49 | + |
| 50 | +```ts |
| 51 | +import { read, readSync } from 'image-js'; |
| 52 | + |
| 53 | +const parsedImage = readSync('example.jpg'); |
| 54 | +const parsedImageAsync = await read('example.jpg'); |
| 55 | +``` |
| 56 | + |
| 57 | +:::tip |
| 58 | +Node.js can also load an image via `fetchURL`. To get more information, take a look at the next section. |
| 59 | +::: |
| 60 | + |
| 61 | +Once the image is loaded, it returns an instance of the `Image` class, so its methods can be applied. |
| 62 | + |
| 63 | +```ts |
| 64 | +const invertedImage = parsedImage.invert(); |
| 65 | +``` |
| 66 | + |
| 67 | +To save an image use `writeSync` or `write` function: |
| 68 | + |
| 69 | +```ts |
| 70 | +import { writeSync, write } from 'image-js'; |
| 71 | + |
| 72 | +writeSync('out.png', image); |
| 73 | +await write('out.png', image); |
| 74 | +``` |
| 75 | + |
| 76 | +Image format is automatically identified based on the extension. In this case it's `'.png'` so the image is saved as a PNG file. |
| 77 | + |
| 78 | +So, in the end you should get a code like this: |
| 79 | + |
| 80 | +```ts |
| 81 | +import { readSync, writeSync } from 'image-js'; |
| 82 | + |
| 83 | +const parsedImage = readSync('example.jpg'); |
| 84 | +const image = parsedImage.invert(); |
| 85 | +writeSync('example.png', image); |
| 86 | +``` |
| 87 | + |
| 88 | +### Loading an image from a web browser |
| 89 | + |
| 90 | +To load an image via a browser, you may use the `fetchURL` function: |
| 91 | + |
| 92 | +```ts |
| 93 | +import { fetchURL } from 'image-js'; |
| 94 | + |
| 95 | +let image = await fetchURL('https:://example.com/image.jpg'); |
| 96 | +image = image.grey(); |
| 97 | +``` |
| 98 | + |
| 99 | +:::info |
| 100 | +To see more methods, visit the ["Features"](./Features/Features.md) category. |
| 101 | +::: |
| 102 | + |
| 103 | +## What's next? |
| 104 | + |
| 105 | +Now that you know how images are loaded and saved, you can deepen your understanding by going through the [Basics](./Basics) category and seeing how different basic elements of ImageJS work. |
| 106 | +You can also broaden your horizons by looking at available [Features](./Features). |
| 107 | + |
| 108 | +If you want to see how ImageJS works in practice, we suggest you visit the [Tutorials](./Tutorials) segment and see for yourself its practical applications. |
0 commit comments