How to rotate an image a set number of degrees in Salesforce Apex
1 min readJul 11, 2020
Rotating images is a common and useful function to have around, but can be difficult to achieve in Salesforce Apex. Rather than dig into the whole mess of code required to set it up from scratch, I will show you how to take a Cloudmersive API and implement it into your project, getting you set up in just a few minutes.
First download this archive, from which you will extract the client folder into your project in Apex.
https://github.com/Cloudmersive/Cloudmersive.APIClient.Apex.ImageRecognition/archive/master.zip
Now we just need to call our function and specify the degrees of rotation and input file:
SwagEditApi api = new SwagEditApi();SwagClient client = api.getClient();// Configure API key authorization: ApikeyApiKeyAuth Apikey = (ApiKeyAuth) client.getAuthentication('Apikey');Apikey.setApiKey('YOUR API KEY');Map<String, Object> params = new Map<String, Object>{'degrees' => 1.2,'imageFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersBlob result = api.editRotate(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}
Super simple.