How to remove EXIF data from an image file in Java

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.





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.

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

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