# PageToolsPlugin

## Content

# Class: PageToolsPlugin

Page Tools Plugin.
Adds the "Page tools" button.

## Example

```html
<script src="gcimageviewer.js"></script></head>
<script src="plugins/pageTools.js"></script>
<script>
  const viewer = new DsImageViewer("#root");
  viewer.addPlugin(new PageToolsPlugin());
</script>
```

## Properties

### viewer

```ts
viewer: ImageViewerAPI;
```

Gets the image viewer instance.
The image viewer instance.

#### Implementation of

```ts
PageToolsPluginAPI.viewer
```

***

### options

```ts
options: PageToolsPluginOptions;
```

Plugin options

#### Implementation of

```ts
PageToolsPluginAPI.options
```

***

### totalRotation

```ts
totalRotation: number;
```

Gets current rotation in degrees.

#### Implementation of

```ts
PageToolsPluginAPI.totalRotation
```

***

### paintLayer

```ts
paintLayer: ImageLayer;
```

Gets the paint layer containing the HTML canvas for drawing the image.

#### Implementation of

```ts
PageToolsPluginAPI.paintLayer
```

***

### isReady

```ts
isReady: boolean;
```

Returns true if the image is loaded into the viewer and the image format is supported by the Image Filters plugin.

#### Implementation of

```ts
PageToolsPluginAPI.isReady
```

***

### naturalSize

```ts
naturalSize: Size;
```

Natural image size.

#### Implementation of

```ts
PageToolsPluginAPI.naturalSize
```

***

### id

```ts
id: PluginType;
```

Unique plug-in identifier.

#### Implementation of

```ts
PageToolsPluginAPI.id
```

## Methods

### rotate()

```ts
rotate(angle): Promise<boolean>;
```

Rotate image.

#### Parameters

##### angle

`number`

Angle to rotate an image.

#### Returns

`Promise`&lt;`boolean`&gt;

#### Implementation of

```ts
PageToolsPluginAPI.rotate
```

***

### crop()

```ts
crop(
   x, 
   y, 
   width, 
   height): Promise<boolean>;
```

Crop image.

#### Parameters

##### x

`number`

Leftmost point of a new image rectangle

##### y

`number`

Topmost point of a new image rectangle

##### width

`number`

Width a new image rectangle

##### height

`number`

Height a new image rectangle

#### Returns

`Promise`&lt;`boolean`&gt;

Whether transformation was applied successfully or not.

#### Implementation of

```ts
PageToolsPluginAPI.crop
```

***

### resize()

```ts
resize(
   width, 
   height, 
   keepAspectRatio): Promise<boolean>;
```

Resize image.

#### Parameters

##### width

`number`

New image width.

##### height

`number`

New image height

##### keepAspectRatio

`boolean`

Explicitly defines a need of keeping an original image aspect ratio. Defaults to true.

#### Returns

`Promise`&lt;`boolean`&gt;

#### Implementation of

```ts
PageToolsPluginAPI.resize
```

***

### flip()

```ts
flip(horizontal, vertical): Promise<boolean>;
```

Flip image.

#### Parameters

##### horizontal

`boolean`

Flip horizontally. True by default.

##### vertical

`boolean`

#### Returns

`Promise`&lt;`boolean`&gt;

Whether transformation was applied successfully or not.

#### Implementation of

```ts
PageToolsPluginAPI.flip
```

***

### flipHorizontal()

```ts
flipHorizontal(): Promise<boolean>;
```

Flip image horizontally.

#### Returns

`Promise`&lt;`boolean`&gt;

Whether transformation was applied successfully or not.

#### Implementation of

```ts
PageToolsPluginAPI.flipHorizontal
```

***

### flipVertical()

```ts
flipVertical(): Promise<boolean>;
```

Flip image vertically.

#### Returns

`Promise`&lt;`boolean`&gt;

Whether transformation was applied successfully or not.

#### Implementation of

```ts
PageToolsPluginAPI.flipVertical
```

***

### isImageFormatSupported()

```ts
isImageFormatSupported(imageFormat, allowUnknown?): boolean;
```

Determines whether the specified image format is supported for modifications.

#### Parameters

##### imageFormat

The image format to check, either as an enum value or string.

`string` | `ImageFormatCode`

##### allowUnknown?

`boolean`

If true, allows unknown formats (ImageFormatCode.Default) to be considered supported.

#### Returns

`boolean`

True if the format is supported for modifications, false otherwise.

#### Remarks

The following formats are explicitly not supported:
- TIFF (ImageFormatCode.TIFF)
- SVG (ImageFormatCode.SVG)
- ICO (ImageFormatCode.ICO)
- GIF (ImageFormatCode.GIF)

#### Examples

```ts
// Check if PNG is supported
const supported = isImageFormatSupported(ImageFormatCode.PNG);
```

```ts
// Check if an unknown format is supported (returns false by default)
const supported = isImageFormatSupported('custom-format');
```

```ts
// Check if an unknown format is supported (returns true when allowUnknown is true)
const supported = isImageFormatSupported('custom-format', true);
```

#### Implementation of

```ts
PageToolsPluginAPI.isImageFormatSupported
```

***

### dispose()

```ts
dispose(): void;
```

Cleans up resources and disposes the plugin.

#### Returns

`void`

#### Implementation of

```ts
PageToolsPluginAPI.dispose
```

***

### removePaintLayer()

```ts
removePaintLayer(): void;
```

Removes and disposes the active paint layer. If no paint layer exists, this method does nothing.

#### Returns

`void`

#### Implementation of

```ts
PageToolsPluginAPI.removePaintLayer
```

***

### initialize()

```ts
initialize(viewer): void;
```

The method is called when the GcImageViewer component is initialized.

#### Parameters

##### viewer

[`ImageViewerAPI`](../interfaces/ImageViewerAPI)

#### Returns

`void`

#### Implementation of

```ts
PageToolsPluginAPI.initialize
```
