How to Convert an Image to TIFF Format using Java
For those of us tasked with making websites load quickly, TIFF format is a bit of a nightmare. However, for those who are manipulating & printing digital images, TIFF is a godsend. If you fall into the latter category, our Image to TIFF conversion API can make a big difference in your image processing operation. This API will convert any number of common image formats — also including PDFs — to TIFF format using only the original file path as an input.
The best part? You can use this API for free on a limited basis — you’ll get 800 free API calls per month when you register a free account on our website, and you won’t have to worry about any hidden financial commitments (you’ll just need to upgrade to a business account to exceed the 800/month limit). With your API key ready to go, all you need to do is follow instructions below to install the API client & structure your API call with complementary, ready-to-run Java code examples.
Our first step is to install the API client with Maven. Let’s first add a reference to our repository in pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
After that, we can wrap up our installation step by adding a reference to our dependency in pom.xml:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Lastly, we can add the imports to the top of our file and call the function. Within the code below, include your API key and file path in their respective fields (indicated by the code comments) and you’re all set:
// 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.ConvertApi;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");ConvertApi apiInstance = new ConvertApi();
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.convertToTiff(imageFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling ConvertApi#convertToTiff");
e.printStackTrace();
}