【发布时间】:2020-02-27 06:39:13
【问题描述】:
我正在使用Jimp 读取如下所示的 JSON 字符串:
如您所见,image 节点是 base64 编码的 JPEG。
我能够成功地将其转换为 TIFF 并保存:
Jimp.read(Buffer.from(inputImage, "base64"), function(err, image) {
image.getBuffer(Jimp.MIME_TIFF, function(error, tiff) {
context.bindings.outputBlob = tiff
...}
但是,当我尝试将 tiff 嵌入到 JSON 对象中时,TIFF 变得乱码:
const response = {
image: tiff.toString('base64'),
correlation: correlation
};
context.bindings.outputBlob = response;
这是完整的代码:
const Jimp = require("jimp");
module.exports = function(context, myBlob) {
const correlation = context.bindings.inputBlob.correlation;
const inputImage = context.bindings.inputBlob.image;
const imageName = context.bindings.inputBlob.imageName;
context.log(
correlation + "Attempting to convert this image to a tiff: " + imageName
);
Jimp.read(Buffer.from(inputImage, "base64"), function(err, image) {
image.getBuffer(Jimp.MIME_TIFF, function(error, tiff) {
const response = {
image: tiff.toString('base64'),
correlation: correlation
};
context.bindings.outputBlob = response;
context.log(
correlation + "Succesfully converted " + imageName + " to tiff."
);
context.done();
});
});
};
我们如何将 tiff 嵌入到 JSON 有效负载中?
如果此输出不可协商,我将如何从保存的有效负载中呈现 tiff?
【问题讨论】:
-
Jimp 调用 UTIF,它读取任何类型的 tiff,但似乎只写入未压缩的 RGBA tiff。通常,解压缩和重新压缩图像不会返回相同的数据。
-
@OrionLawlor 谢谢。在那种情况下,保存图像后,我将如何渲染它?
-
您是否尝试将其呈现为函数的响应,例如通过 context.res?
-
@search-learn 是的
标签: javascript node.js json azure-functions jimp