How to Convert SVG to JPEG2000 with Java REST API

This tutorial shows you how to convert SVG to JPEG2000 with Java REST API. SVG (Scalable Vector Graphics) is a vector image file format that is used to create two-dimensional graphics and images. It is an XML-based file format that supports interactivity and animation. SVG files are widely used to create logos, icons, charts, and diagrams. They are resolution independent, meaning that they can be resized without losing any image quality.

Whereas, JPEG2000 is a file format that is an improved version of the most common JPEG format. It uses wavelet compression to reduce file size while still retaining high image quality. This makes it especially useful for applications such as digital archiving, medical imaging, and satellite imagery. It supports higher bit depths and greater color accuracy than the standard JPEG format, and also supports lossless as well as lossy compression. If you would like SVG to JPEG2000 Conversion in Java Low Code API then this can be accomplished with the help of the following snippet.

Prerequisite

Steps to Convert SVG to JPEG2000 in Java REST API

  1. Set Client ID and Client Secret for the API
  2. Create an object of ImagingAPI class with client credentials
  3. Specify input and output files
  4. Read input SVG file and upload to cloud storage
  5. Create an object of ConvertImageRequest with input and output file formats
  6. Call convertImage method to Convert SVG to JPEG2000 using REST API
  7. Save the output JPEG2000 file on local disk

Code for SVG to JPEG2000 Conversion in Java Low Code API

String ClientID = Client.getID(); //replace Client.getID() with your own client ID here
String ClientSecret = Client.getSecret(); //replace Client.getSecret() with your own client secret here
String APIBaseUrl="https://api.aspose.cloud";
String Local_Path = "C:/Temp/";
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl);
// Input & output file names
String inputFileName = "SVGtoJPEG2000.svg";
String outputFileName = "SVGtoJPEG2000.jp2";
try {
// Upload local image to Cloud Storage
File inputFile = new File(Local_Path + inputFileName);
FileInputStream inputFileStream = new FileInputStream(inputFile);
byte[] inputImageData = IOUtils.toByteArray(inputFileStream);
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null);
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest);
String outputFormat = "jp2";
String remoteFolder = null; // Input file is saved at the root of the storage
String remoteStorage = null; // Cloud Storage name
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage);
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest);
// Save exported image to local storage
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName);
fileOutputStream.write(convertedImageData);
fileOutputStream.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}

The above code snippet lets you convert SVG to JPEG2000 with Java REST API. You merely have to upload SVG file with the help of the Aspose.Imaging REST API SDK and download output JPEG2000 file to save it locally.

The above SVG to JPEG2000 Conversion can be exploited with any no code or low code apps on Windows, Linux, or Mac.

Another relevant feature can be found at the following URL: How to Convert JPG to JPEG2000 with Java REST API

 English