# @toast-ui/vue-image-editor

> TOAST UI Image-Editor for Vue

Latest version **3.15.2** (published 2021-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install @toast-ui/vue-image-editor
pnpm add @toast-ui/vue-image-editor
yarn add @toast-ui/vue-image-editor
bun add @toast-ui/vue-image-editor
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.15.2 |
| Published | 2021-10-20 |
| First published | 2018-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 40.8 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 7663 |
| Author | NHN. FE Development Team |
| Maintainers | nhnent, codepink |

## Links

- npm: https://www.npmjs.com/package/@toast-ui/vue-image-editor
- Repository: https://github.com/nhn/tui.image-editor
- Issues: https://github.com/nhn/tui.image-editor/issues
- npm.io page: https://npm.io/package/@toast-ui/vue-image-editor

## Dependencies (2)

- [fabric](https://npm.io/package/fabric.md) ^4.2.0
- [tui-image-editor](https://npm.io/package/tui-image-editor.md) ^3.15.2

## Recent versions

- 3.15.2 (latest) — 2021-10-20
- 3.15.1 — 2021-10-18
- 3.15.0 — 2021-07-28
- 3.14.3 — 2021-04-08
- 3.14.2 — 2021-03-25
- 3.14.1 — 2021-03-19
- 3.14.0 — 2021-03-08
- 3.13.0 — 2021-03-05
- 3.12.0 — 2021-02-22
- 1.3.0 — 2020-12-09
- 1.2.1 — 2020-11-16
- 1.2.0 — 2020-02-13
- 1.0.2 — 2019-01-02
- 1.0.1 — 2018-11-28
- 1.0.0 — 2018-10-26

## README

# Vue wrapper for TOAST UI Image Editor

> This is a Vue component wrapping [TOAST UI Image Editor](https://github.com/nhn/tui.image-editor).

[![npm version](https://img.shields.io/npm/v/@toast-ui/vue-image-editor.svg)](https://www.npmjs.com/package/@toast-ui/vue-image-editor)

## 🚩 Table of Contents

- [Collect statistics on the use of open source](#collect-statistics-on-the-use-of-open-source)
- [Install](#-install)
  - [Using npm](#using-npm)
- [Usage](#-usage)
  - [Load](#load)
  - [Implement](#implement)
  - [Props](#props)
  - [Events](#events)
  - [Method](#method)

## Collect statistics on the use of open source

TOAST UI ImageEditor applies Google Analytics (GA) to collect statistics on the use of open source, in order to identify how widely TOAST UI ImageEditor is used throughout the world. It also serves as important index to determine the future course of projects. location.hostname (e.g. > “ui.toast.com") is to be collected and the sole purpose is nothing but to measure statistics on the usage. To disable GA, use the following `usageStatistics` option when creating the instance.

```js
const options = {
    ...
    usageStatistics: false
}

const imageEditor = new tui.ImageEditor('#tui-image-editor-container', options);
```

Or, include [`tui-code-snippet`](https://github.com/nhn/tui.code-snippet)(**v1.4.0** or **later**) and then immediately write the options as follows:

```js
tui.usageStatistics = false;
```

## 💾 Install

### Using npm

```sh
npm install --save @toast-ui/vue-image-editor
```

> **If you install other packages**, you may lose dependency on fabric. You need to **reinstall the fabric**.

    ```
    npm install --no-save --no-optional fabric@~4.2.0
    ```

## 🔡 Usage

### Load

- Using namespace

  ```js
  const ImageEditor = toastui.ImageEditor;
  ```

- Using module

  ```js
  // es modules
  import { ImageEditor } from '@toast-ui/vue-image-editor';

  // commonjs require
  const { ImageEditor } = require('@toast-ui/vue-image-editor');
  ```

- Using `<script>`

  If you just add javascript file to your html, you use `toastui-vue-image-editor.js` downloaded. Insert `toastui-vue-image-editor.js` with `vue` in your html like this:

  ```html
  <script src="https://cdn.jsdelivr.net/npm/vue"></script>
  <script src="path/to/toastui-vue-image-editor.js"></script>
  ```

- Using only Vue wrapper component (Single File Component)

  `toastui-vue-image-editor.js` has all of the tui.ImageEditor. If you only need vue wrapper component, you can use `@toast-ui/vue-image-editor/src/ImageEditor.vue` like this:

  ```js
  import ImageEditor from '@toast-ui/vue-image-editor/src/ImageEditor.vue';
  ```

### Implement

First insert `<tui-image-editor>` in the template or html. `includeUi` and `options` props are required.

```html
<tui-image-editor :include-ui="useDefaultUI" :options="options"></tui-image-editor>
```

Load ImageEditor component and then add it to the `components` in your component or Vue instance.

```js
import 'tui-color-picker/dist/tui-color-picker.css';
import 'tui-image-editor/dist/tui-image-editor.css';
import { ImageEditor } from '@toast-ui/vue-image-editor';

export default {
  components: {
    'tui-image-editor': ImageEditor,
  },
  data() {
    return {
      useDefaultUI: true,
      options: {
        // for tui-image-editor component's "options" prop
        cssMaxWidth: 700,
        cssMaxHeight: 500,
      },
    };
  },
};
```

### Props

You can use `includeUi` and `options` props. Example of each props is in the [Getting Started](../../docs/Basic-Tutorial.md).

- `includeUi`

  | Type    | Required | Default |
  | ------- | -------- | ------- |
  | Boolean | X        | true    |

  This prop can contained the `includeUI` prop in the option. You can see the default UI.

- `options`

  | Type   | Required | Default                                 |
  | ------ | -------- | --------------------------------------- |
  | Object | X        | { cssMaxWidth: 700, cssMaxHeight: 500 } |

  You can configure your image editor using `options` prop. For more information which properties can be set in `options`, see [options of tui.image-editor](https://nhn.github.io/tui.image-editor/latest/ImageEditor).

### Events

- addText: The event when 'TEXT' drawing mode is enabled and click non-object area.
- mousedown: The mouse down event with position x, y on canvas
- objectActivated: The event when object is selected(aka activated).
- objectMoved: The event when object is moved.
- objectScaled: The event when scale factor is changed.
- redoStackChanged: Redo stack changed event
- textEditing: The event which starts to edit text object.
- undoStackChanged: Undo stack changed event

```html
<tui-image-editor ... @addText="onAddText" @objectMoved="onObjectMoved"> </tui-image-editor>
```

```js
...
methods: {
    onAddText(pos) {
        ...
    },
    onObjectMoved(props) {
        ...
    }
}
...
```

For more information such as the parameters of each event, see [event of tui.image-editor](https://nhn.github.io/tui.image-editor/latest/ImageEditor#event-addText).

### Method

For use method, first you need to assign `ref` attribute of element like this:

```html
<tui-image-editor ref="tuiImageEditor" :options="options"></tui-image-editor>
```

After then, you can use methods through `this.$refs`. We provide `getRootElement` and `invoke` methods.

- `getRootElement`

  You can get root element of image editor using this method.

  ```js
  this.$refs.tuiImageEditor.getRootElement();
  ```

- `invoke`

  If you want to more manipulate the ImageEditor, you can use `invoke` method to call the method of tui.ImageEditor. First argument of `invoke` is name of the method and second argument is parameters of the method. To find out what kind of methods are available, see [method of tui.ImageEditor](https://nhn.github.io/tui.image-editor/latest/ImageEditor).

  ```js
  const drawingMode = this.$refs.tuiImageEditor.invoke('getDrawingMode');

  this.$refs.tuiImageEditor.invoke('loadImageFromURL', './sampleImage.png', 'My sample image');

  this.$refs.tuiImageEditor.invoke('startDrawingMode', 'FREE_DRAWING', {
    width: 10,
    color: 'rgba(255, 0, 0, 0.5)',
  });
  ```

---
_Source: https://npm.io/package/@toast-ui/vue-image-editor · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
