I have a class called Order
that contains an array of pointers towards another class called PrescriptionImage
. I want to query all these images and add a watermark to them. After that I need to save these images back (basically update them).
I have not been able to find a way to add a watermark to the images and am a bit confused about image handling via cloud code. A lot of the tutorials use it for javascript and make use of html codes.
Parse.Cloud.define("stampPrescription", function(request, response){
// String that contains the current date
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
var dateAsString = dd+"-"+mm+"-"+yyyy;
// object id for the Order object being called
var orderObjectId = request.params.orderObjectId;
var address = request.params.address;
var order = Parse.Object.extend("Order");
var queryForOrder = new Parse.Query(order);
queryForOrder.include("Prescriptionimage");
queryForOrder.get(orderObjectId , {
success: function(results){
console.log("value found is "+results.id);
var rxImages = results.get("prescriptionImageArray");
for (var i = 0; i < rxImages.length; i++) {
var imageFile = rxImages[i];
// I retrive the images and store in a variable
// TODO: Need help with below line
// place watermark with dateAsString and address at bottom of the image
}
response.success("done";
}, //Ends block for successfuly query
error: function(e){
console.log("Error in query "+e.message);
respone.error("Error in query "+e.message);
}
}); // Ends queryForOrder block
}); //Ends the function
My main issue is that curently I place a watermark on the image in the android phones (client side) by using `paint1 in android. I now want to shift this code to server side i.e. cloud code in parse for efficiency and speed. Can someone please help me out with this? Currently below is the code I am using in android to modify the bitmaps.
public Bitmap mark(Bitmap src, int alpha, int size, boolean underline) {
int w = src.getWidth();
int h = src.getHeight();
Bitmap result = Bitmap.createBitmap(w, h, src.getConfig());
Canvas canvas = new Canvas(result);
canvas.drawBitmap(src, 0, 0, null);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#551A8B"));
paint.setAlpha(alpha);
paint.setTextSize(size);
paint.setAntiAlias(true);
paint.setUnderlineText(underline);
final Calendar c = Calendar.getInstance();
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss");
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
String currentTime = time.format(c.getTime());
String currentDate = dateFormat.format(c.getTime());
canvas.drawText(name, w / 2, 3 * h / 4 - 15, paint);
canvas.drawText(currentTime, w / 2, 3 * h / 4 + 5, paint);
canvas.drawText(currentDate, w / 2, 3 * h / 4 + 25, paint);
canvas.drawText(chemistAddress1, w / 2, 3 * h / 4 + 45, paint);
return result;
}
If I need to mark multiple images and then upload, it slows down the process significantly and takes up much more memory. I dont want to risk OOM
exception and so want to shift above process to cloud code but I cannot find an equivalent of the above that I can run on parse cloud code.