How to rotate an image a set number of degrees in Salesforce Apex

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.

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.

Image for post
Image for post

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