# Save Image

## Content

DsImageViewer allows you to save or download an image using the **Save** button (![save-button](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-button.c688dc.png)) on the toolbar.
![save-image](https://cdn.mescius.io/document-site-files/images/b882ef15-67ec-41e0-8e66-2977bfeb3645/save-image.28aafd.gif)
You can also save the image by using [save ](https://developer.mescius.com/document-solutions/javascript-image-viewer/api/classes/DsImageViewer#save)method programmatically. This method saves the image to the local disk in its existing state. However, you can also save the unedited original image by setting the [original ](https://developer.mescius.com/document-solutions/javascript-image-viewer/api/classes/DsImageViewer#original-1)parameter to **true**.

```javascript
function loadImageViewer() {
   
   // Initialize DsImageViewer.
   var viewer = new DsImageViewer("#imageviewer");

   // Save the image.
   viewer.save("downloadedimage.png");
}
```

## Save Image in Alternative Formats

DsImageViewer allows you to save or download an image in different formats using **Save As** drop-down menu options (![save-as-drop-down-menu](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-drop-down-menu.dad103.png)) on the toolbar.
![save-as-image](https://cdn.mescius.io/document-site-files/images/b882ef15-67ec-41e0-8e66-2977bfeb3645/save-as-image.4812c1.gif)
Save As drop-down menu provides the following options to convert the image to the required format:

| **Save As Options** | **Description** |
| --------------- | ----------- |
| ![save-as-png](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-png.6ddc60.png) | Saves the image in PNG format. |
| ![save-as-jpg](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-jpg.57c41f.png) | Saves the image in JPG format. |
| ![save-as-webp](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-webp.42c5d1.png) | Saves the image in WEBP format. |
| ![save-as-gif](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-gif.e59e5c.png) | Saves the image in GIF format. |
| ![save-as-bmp](https://cdn.mescius.io/document-site-files/images/108467c9-c140-4db8-96cd-56d9ec3b6e1c/save-as-bmp.c4b236.png) | Saves the image in BMP format. |

>type=warning
> **Note:** DsImageViewer dynamically adjusts the menu items depending on the formats supported by the browser.

You can also save the image in different formats by using [convertToFormat](https://developer.mescius.com/document-solutions/javascript-image-viewer/api/type-aliases/ImageMimeType) parameter of [save ](https://developer.mescius.com/document-solutions/javascript-image-viewer/api/classes/DsImageViewer#save)method programmatically. This method also allows you to provide a custom name using fileName parameter.

```javascript
function loadImageViewer() {
   
   // Initialize DsImageViewer.
   const viewer = DsImageViewer.findControl("#root");

   // Save the modified image with a custom file name and in JPEG format.
   viewer.save({ fileName: "enhanced-lake.jpeg", convertToFormat: "image/jpeg" });
}
```

## Customize Save Button and Save As Options

DsImageViewer also allows you to customize the behavior and to enable or disable the Save button drop-down menu using [saveButton](https://developer.mescius.com/document-solutions/javascript-image-viewer/api/interfaces/ViewerOptions#savebutton) option. Refer to the following example codes for different customizations:

### Example 1: Hide "Save As" Drop-down Menu

```javascript
function loadImageViewer() {
   
   // Hide Save As drop-down menu.
   var viewer = new DsImageViewer("#root", { saveButton: { saveAsMenu: false } });
}
```

### Example 2: Restrict "Save As" Image Formats to PNG and BMP

```javascript
function loadImageViewer() {
   
   // Restrict Save As image formats to PNG and BMP.
   var viewer = new DsImageViewer("#root", { saveButton: { saveAsMenu: { availableFormats: ["image/png", "image/bmp"] } } });
}
```

#### Limitations

* WEBP format is not supported on macOS and iOS Safari browsers with version 13 or lower.
* DsImageViewer supports the conversion of static images only.