How to convert Photoshop PSD to PNG in Salesforce Apex

Cloudmersive
2 min readJul 11, 2020

Apex is a great language for many things, but converting image formats is generally not considered one of them. If you want to spend all day figuring out how to parse PSD format and rendering it into an image, that’s fine, but I do have a better solution that I can show you. By using an API to take the brunt of the work, we can finish up its implementation in just a few minutes.

We begin with installation of the client. Go to its github page, linked below, download, and copy the client folder into your project:

https://github.com/Cloudmersive/Cloudmersive.APIClient.Apex.Convert/archive/master.zip

Now it’s time to call the function convertImageImageFormatConvert, like so:

SwagConvertImageApi api = new SwagConvertImageApi();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>{'format1' => 'format1_example','format2' => 'format2_example','inputFile' => Blob.valueOf('Sample text file\nContents')};try {// cross your fingersBlob result = api.convertImageImageFormatConvert(params);System.debug(result);} catch (Swagger.ApiException e) {// ...handle your exceptions}

Set your format1 to PSD and format2 to PNG, and you are good to go! This API also supports over 100 other image formats, so take a look at the documentation section for more info.

--

--

Cloudmersive

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