How to Convert GIF to JPEG2000 with Java REST API

The following step by step tutorial shows you how to convert GIF to JPEG2000 with Java REST API. GIF (Graphics Interchange Format) is a bitmap image format developed by CompuServe in 1987. It is widely used to display images on the web and is also commonly used for simple animations. GIFs support up to 8 bits per pixel for each image, allowing a single image to reference a palette of up to 256 different colors.

On the other hand, JPEG2000 is a file format for digital images developed by the Joint Photographic Experts Group (JPEG). It is a modern image compression standard that offers several advantages over the older JPEG format, such as superior compression, better image quality, and support for a wide range of features, including animation and interactivity. JPEG2000 files are typically smaller than JPEG files, making them ideal for web graphics and streaming multimedia. If you’re interested in GIF to JPEG2000 Conversion in Java Low Code API then the same can be achieved with the help of below code.

Prerequisite

Steps to Convert GIF 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 GIF file and upload to cloud storage
  5. Create an object of ConvertImageRequest with input and output file formats
  6. Call convertImage method to Convert GIF to JPEG2000 using REST API
  7. Save the output JPEG2000 file on local disk

Code for GIF 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 = "GIFtoJPEG2000.gif";
String outputFileName = "GIFtoJPEG2000.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 sample code in this post helps you to convert GIF to JPEG2000 with Java REST API. You just have to upload GIF file with the help of the Aspose.Imaging REST API SDK and download output JPEG2000 file to save it locally.

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

The following link shows a similar feature that might be helpful to you: How to Convert JPEG2000 to PDF with Java REST API

 English