wirlHow to apply swirl distortion on an image in Java

Wild distortion effects can be a great way to up the interest value of a photo. Today we will be covering how to achieve a swirl effect in just a matter of minutes. Get ready to save a lot of time!

First up, we need to add two references to our Maven POM file. These will be used by Jitpack to dynamically install the library we need for our API.

Repository reference


Dependency reference


With our library established, we can now invoke filterSwirl and define our degrees of swirl:

// 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: ApikeyApiKeyAuth 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)//Apikey.setApiKeyPrefix("Token");FilterApi apiInstance = new FilterApi();Integer degrees = 56; // Integer | Degrees of swirlFile imageFile = new File("/path/to/file"); // File | Image file to perform the operation on.  Common file formats such as PNG, JPEG are supported.try {byte[] result = apiInstance.filterSwirl(degrees, imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling FilterApi#filterSwirl");e.printStackTrace();}

And it’s really that easy! How about a quick example image?

Image for post
Image for post

Now let’s apply a distortion of 100 degrees and see what we get.

Image for post
Image for post

Written by

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

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