How to remove EXIF data from an image file in Java

Cloudmersive
2 min readJan 26, 2020

--

Exchangeable image file format (EXIF) data, while useful, can be a real nuisance to remove. Let us look at how to set this up with just a few lines of code and an API.

First off, we need to add some references to our pom.xml file. This will allow Jitpack to install our library so that we can continue.

Repository

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

Dependency

<dependencies>
<dependency>
<groupId>com.github.Cloudmersive</groupId>
<artifactId>Cloudmersive.APIClient.Java</artifactId>
<version>v2.75</version>
</dependency>
</dependencies>

With that done, all we have to do is call editRemoveExifData:

// 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;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");EditApi apiInstance = new EditApi();File 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.editRemoveExifData(imageFile);System.out.println(result);} catch (ApiException e) {System.err.println("Exception when calling EditApi#editRemoveExifData");e.printStackTrace();}

Done! Our file will now be stripped of its EXIF data and ready for use. If this tutorial saved you some time, you may also like our other image-related APIs, which cover everything from converting between image formats to adjusting gamma dynamically.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

Responses (1)