[我目前正在尝试一些脚本,以从文件柜中获取图像,将URL推入HTML画布,检索宽度/高度(以插入自定义字段并调整原始图像的大小。
上面在客户端脚本中可以-没问题。
但是,我想知道的是
如何将调整大小后的图像作为文件对象(N /文件)捕获,而无需用户干预将其保存到文件柜中。
是否有一种从服务器端上下文使用HTML画布的方法。
对于#1,这似乎很困难,因为N / file模块不可用于ClientScript,所以可能需要推送到SuiteLet?
到目前为止,我的一些代码
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.onload = function () {
// set size proportional to image
canvas.height = canvas.width * (img.height / img.width);
// step 1 - resize to 50%
var oc = document.createElement('canvas'),
octx = oc.getContext('2d');
oc.width = img.width * 0.5;
oc.height = img.height * 0.5;
octx.drawImage(img, 0, 0, oc.width, oc.height);
// step 2
octx.drawImage(oc, 0, 0, oc.width * 0.5, oc.height * 0.5);
// step 3, resize to final size
ctx.drawImage(oc, 0, 0, oc.width * 0.5, oc.height * 0.5, 0, 0, canvas.width, canvas.height);
var imageContent = canvas.toDataURL('image/png');
var decodedContent = btoa(imageContent);
scriptContext.currentRecord.setValue({fieldId:'custitem_image1_width', value: img.width})
scriptContext.currentRecord.setValue({fieldId:'custitem_image1_height', value: img.height})
img.src = scriptContext.currentRecord.getValue({fieldId:'custitem_image1_thumb_url'})
上面在CSS pageInit中当前正在运行,并且我有一个单独的UES beforeLoad脚本创建了INLINEHTML字段custpage_htmlcanvas
。
var fileObj = file.create({
name: 'test.txt',
fileType: file.Type.PLAINTEXT,
contents: 'Hello World\nHello World',
description: 'This is a plain text file.',
encoding: file.Encoding.UTF8,
folder: 30,
isOnline: true
});