7

I am currently working on a project to create a (not prepaid) postage label. In java, I would go about doing this by creating a bufferedimage and adding various other images to it to create what I want. What I want is to put text, converted to an image, onto a template letter, to make a proper postage label.

For example, imagine I was given a document with blank spaces such as:

"Name: _________"

This document is in the form of an image, and I want to use apex and visualforce (the page is already constructed, I am just stuck at the image manipulation part) to add whatever name the user types in onto the image and pack it and email the new image.

The question I have here is: where do I even start? Java is a little nicer when it comes to image manipulation, as far as I can see. I've looked into using a web service and sending a soapxml request to return a proper encoded image, but I haven't found a web service that can do this.

Any pointers would be nice. Thanks.

2 Answers 2

12

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.

2

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.

1
  • 1
    You get my vote. This is trivial in almost every server-side language ever... except Apex Code.
    – sfdcfox
    Apr 1, 2016 at 17:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .