How to Remove EXIF (Including Geolocation) Data from an Image using Java
Sometimes, image files contain a little more information than we want them to. While way-too-specific information like geolocation data can be disabled on your personal phone to help avoid this problem, many old/existing images will unfortunately retain that data, making it available to anyone online who chooses to look for it. Thankfully, you can easily remove EXIF data (containing geolocation data) from any image using our EXIF Removal API, ensuring images are secure before uploading them to a public location online. To use this API, you’ll just need to register a free account on our website & authenticate your API key in the code examples below. The below demonstration will help you structure your API call in Java, but you can also find transposed code available in 12+ additional programming languages on our API console page.
Before we call the function, we first need to install the API client. We can begin to do so by adding a reference to the pom.xml repository:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
And we can complete installation by adding a reference to the pom.xml dependency:
<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v4.25</version>
</dependency>
</dependencies>
Now we can add our imports to the top of our file:
// 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.EditApi;
And call the API, passing through our input file & API key parameters:
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");EditApi apiInstance = new EditApi();
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.editRemoveExifData(imageFile);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EditApi#editRemoveExifData");
e.printStackTrace();
}
And that’s it, you’re done — no more code required.