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:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Next include a reference in the dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
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)
//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();
}
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.