Photo Filtering API: How to Swirl Distort an Image with Java

Whether it’s for a professional project, or just for fun, everyone loves putting filters on photos. If you’re looking for an easy way to incorporate simple filter operations into your application, we’ve got you covered.

With the Java code snippets & brief instructions provided below, you can easily take advantage of our Swirl effect API, which will distort an input image by a specified number of degrees. This is one of eight Filter APIs available for free to any developer with a free-tier Cloudmersive account.

To get started, begin installing the Java SDK with Maven. Add a reference to the repository in pom.xml:

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Next, add one to the dependency in pom.xml:

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>

To finish up, include the import classes and then 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)
//Apikey.setApiKeyPrefix("Token");
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);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling FilterApi#filterSwirl");
e.printStackTrace();
}

Just like that, you’re in control of a simple & useful Image filtering API. Check out our website & API documentation page for more utility APIs like this one.

--

--

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
Cloudmersive

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