Skip to content

Instantly share code, notes, and snippets.

@aspose-imaging-cloud-examples
Last active May 24, 2022 09:36

Aspose.Imaging.Cloud NodeJs API allows programmatically convert your jpeg2000 images to various image formats with high quality in your NodeJs application or Web service.

You can:

  • convert jpeg2000 to file;
  • convert jpeg2000 to stream;

Interested ?

You may go further at : https://products.aspose.cloud/imaging/nodejs/

import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "apng";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "apng";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "apng";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "apng";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "bmp";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "bmp";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "bmp";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "bmp";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "dicom";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "dicom";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "dicom";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "dicom";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "gif";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "gif";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "gif";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "gif";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "jpeg";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "jpeg";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "jpeg";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "jpeg";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "jpg";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "jpg";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "jpg";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "jpg";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "pdf";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "pdf";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "pdf";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "pdf";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "png";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "png";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "png";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "png";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "psd";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "psd";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "psd";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "psd";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "tga";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "tga";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "tga";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "tga";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "tiff";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "tiff";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "tiff";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "tiff";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
import * as fs from "fs";
import * as path from "path";
import {ImagingBase} from "./imaging-base";
import {
ConvertImageRequest, CreateConvertedImageRequest,
ImagingApi,
} from "@asposecloud/aspose-imaging-cloud";
const ImageFileName = "example_image.jpeg2000";
const ImagesFolder = "ExampleImages";
const CloudFolder = "CloudImages";
const OutputFolder = "Output";
// Get ClientId and ClientSecret from https://dashboard.aspose.cloud/
// or use on-premise version (https://docs.aspose.cloud/imaging/getting-started/how-to-run-docker-container/)
const api = new ImagingApi(clientSecret, clientId, "https://api.aspose.cloud");
/**
* Convert an image to another format.
*/
public async ConvertImageFromStorage() {
const localInputImage = fs.readFileSync(path.join(ImagesFolder, ImageFileName));
const uploadFileRequest = new UploadFileRequest({path: path.join(CloudFolder, imageName), file: image});
const result = await this.api.uploadFile(uploadFileRequest);
if (result.errors.length > 0)
console.log(`Uploading errors count: ${result.errors.length}`
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "webp";
const folder = this.CloudFolder; // Input file is saved at the desired folder in the storage
const storage = undefined; // Cloud Storage name
const request = new ConvertImageRequest({name: ImageFileName, format, folder, storage});
const convertedImage = await this.api.convertImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "webp";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
/**
* Convert an image to another format. Image data is passed in a request stream.
*/
public async CreateConvertedImageFromRequest() {
// Please refer to https://docs.aspose.cloud/imaging/supported-file-formats/#convert
// for possible output formats
const format = "webp";
const outPath = undefined; // Path to updated file (if this is empty, response contains streamed image)
const storage = undefined; // Cloud Storage name
const inputStream = fs.readFileSync(path.resolve(ImagesFolder, ImageFileName));
const request = new CreateConvertedImageRequest({imageData: inputStream, format, outPath, storage});
const convertedImage = await this.api.createConvertedImage(request);
// Save the image file to output folder
const convertedImageName = ImageFileName.substr(0, ImageFileName.lastIndexOf(".")) + "webp";
const filePath = path.resolve(path.join(OutputFolder, convertedImageName));
fs.writeFile(filePath, convertedImage, (err) => {
if (err) {
throw err;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment