Image manipulation in Apex

I'm going to go straight to the point here: Apex Code has very little utility in the way of dealing with binary data, and even less with trying to manipulate that binary data. You might be able to decode a fairly small GIF image, manipulate some pixels, and re-encode it within the governor limits. JPEG and PNG are probably less likely to be decoded/encoded in time. Apex Code simply isn't designed to handle binary data. I barely figured out how to determine if a PDF file was "signed" or not, and even that was a pretty miserable hack.

So, what's a developer to do? Write it in JavaScript, and drop it right in the middle of a Visualforce or Lightning page. You're not going to be able to do this inside a trigger or batch process, but for on-the-spot editing, it'd be painless. Create a new HTMLCanvas, load your images into Image variables, render the background to the canvas, use some fillText to supply the user values into the image, and then toDataURL to get an updated copy of your image with the merged data. From there, you can do whatever you want with it: print it, save it as an attachment to a record, email it as an attachment, and so on.


You could vote for the Idea : Apex Image Processing

Adding an image processing library to apex would be very helpful for creating thumbnails and resizing images for applications that could use it.