Image Processing API: Resize an Image with Java

For this simple Image Resizing operation, all you need to do is specify the new width and height of the image file you want to resize. With code samples provided below, you can easily create a custom-code connection in Java and put your Image resizing needs to rest in the long term.

To begin the Java SDK installation with Maven, start by adding a reference to the repository in pom.xml:


Then add one to the dependency in pom.xml:


To finish the process, just copy in the import classes and call the function:

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ResizeApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
ResizeApi apiInstance = new ResizeApi();
Integer width = 56; // Integer | Width of the output image - final image will be exactly this width
Integer height = 56; // Integer | Height of the output image - final image will be exactly this height
File imageFile = new File("/path/to/inputfile"); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try {
byte[] result = apiInstance.resizeResizeSimple(width, height, imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling ResizeApi#resizeResizeSimple");

All done. If it’s your first time using a Cloudmersive API, head to our website Home — Cloudmersive APIs and create a free account (with zero financial obligations) to receive a limit of 800 API calls per month.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.