I need help, please...
I'm working on mobile client-side AddImageWatermark function for my Image Utils Mobile component.
All other of my async JS function works with $resolve();
Only this function throw error: $resolve is not defined.
OML is attached.
Platform Server: P10 Version 10.0.302.0 (Java stack)
Service Studio: 10.0.407.0
Code Snippet
var imgW = document.createElement("img"); imgW.onload = function () { var watermark = document.createElement("img"); watermark.onload = function () { var canvas = document.createElement('canvas'); var ctx = canvas.getContext("2d"); var opacity = (255/(100/$parameters.opacity)); // Apply Transparency if ($parameters.opacity != 100) { canvas.width = watermark.width || watermark.offsetWidth; canvas.height = watermark.height || watermark.offsetHeight; ctx.drawImage(watermark, 0, 0); var image = ctx.getImageData(0, 0, canvas.width, canvas.height); var imageData = image.data, length = imageData.length; for(var i=3; i < length; i+=4){ imageData[i] = (imageData[i]<opacity)?imageData[i]:opacity; } image.data = imageData; ctx.putImageData(image, 0, 0); watermark.onload = null; watermark.src = ""; watermark.src = canvas.toDataURL(); // assign img attributes to the transparent watermark // because browsers recalculation doesn't work as fast as needed watermark.width = canvas.width; watermark.height = canvas.height; } canvas.width = imgW.width || imgW.offsetWidth; canvas.height = imgW.height || imgW.offsetHeight; ctx.drawImage(imgW, 0, 0); var position = $parameters.position, x = 0, y = 0; if(position.indexOf("top")!=-1) y = 10; else y = canvas.height-watermark.height-10; if(position.indexOf("left")!=-1) x = 10; else x = canvas.width-watermark.width-10; ctx.drawImage(watermark, x, y); var imageWatermarked = canvas.toDataURL(); imageWatermarked = imageWatermarked.substring(imageWatermarked.indexOf(',') + 1); $parameters.watermarkedImage = imageWatermarked; $resolve(); }; watermark.setAttribute('crossOrigin', 'anonymous'); watermark.src=$parameters.watermarkPath; }; imgW.setAttribute('crossOrigin', 'anonymous'); imgW.src="data:image/png;base64,"+$parameters.image;
Hi Harlin,
Thanks for reporting this issue! You've uncovered a bug related to how we infer a couple of things from the JS code you write in the node, e.g. whether $resolve is being used or not. We'll work on fixing this!
For now, and as a workaround, please remove all comments from the code you wrote and you should be alright.
Let me know if that works for you.
Cheers,
Sérgio
Anyone?
I follow this article for asynchronous Javascript:
https://success.outsystems.com/Documentation/10/Extensibility_and_Integration/JavaScript/Extend_Your_Mobile_App_Using_JavaScript/Defining_Asynchronous_JavaScript_Code
Maybe I should create support ticket...
Hi Sérgio,
Yes removing all comments allow $resolve() to work..
Thanks.
Why this bug still exists????????
Just lost a couple of hours in a similar issue. In my case it was due to a missing ' inside a string.
This code does not work:
console.log(`Random comment '${var}`);
$resolve();
While this does (notice the ' after {var});
console.log(`Random comment '${var}'`);