How to Swirl Distort an Image using Java

There are dozens of common effects you can create on an image by simply manipulating its pixels — all while the file remains compressed & unopened. Using our Swirl Distort API, you can customize the degree to which your image looks twisted/swirled around by specifying an integer value in the degrees parameter. It’s simple & easy to use this API — all you need to do is copy & paste code examples provided below in this article to structure your API call in Java. The final thing you’ll need is a Cloudmersive API key, which you can get for free by registering a free account on our website (this account comes with a limit of 800 API calls per month — perfect for getting smaller scale projects off the ground).

Let’s begin by installing the API client. Include a reference in the repository in pom.xml:


Next include a reference in the dependency in pom.xml:


With installation complete, include the imports at the top of your file & 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.FilterApi;
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)
FilterApi apiInstance = new FilterApi();
Integer degrees = 56; // Integer | Degrees of swirl
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.filterSwirl(degrees, imageFile);
} catch (ApiException e) {
System.err.println("Exception when calling FilterApi#filterSwirl");

Make sure to include your API key where instructed in the code comments, and specify any integer you wish within the degrees field. Then you’re all done — no more code required.



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.