var base64str="data:image/jpeg;base64,***"//base64 format of the image
var buf = Buffer.from(base64str, 'base64');
jimp.read(buf, (err, image) => {
if (err) throw err;
else {
image.crop(140, 50, 200, 280)
.quality(100)
.getBase64(jimp.MIME_JPEG, function(err, src) {
console.log("rb is \n")
console.log(src);
})
}
})
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 npm 中的 jimp 包来裁剪图像的 base64 格式,但出现如下错误:
Error: Could not find MIME for Buffer <null>
at Jimp.parseBitmap (D:\Node\image-crop\node_modules\@jimp\core\dist\utils\image-bitmap.js:108:15)
at new Jimp (D:\Node\image-crop\node_modules\@jimp\core\dist\index.js:425:32)
at _construct (D:\Node\image-crop\node_modules\@jimp\core\dist\index.js:100:393)
at D:\Node\image-crop\node_modules\@jimp\core\dist\index.js:932:5
at new Promise (<anonymous>)
at Function.Jimp.read (D:\Node\image-crop\node_modules\@jimp\core\dist\index.js:931:10)
at Object.<anonymous> (D:\Node\image-crop\index.js:46:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js …
Run Code Online (Sandbox Code Playgroud) 我有一个azure函数,在index.js中,我有以下代码
module.exports = function (context, req) {
const createHandler = require('azure-function-express').createHandler;
const app = require('express')();
app.get("/home", (req, res) => {
const y = { "name": "name", "dob": "ddmmyyyy" }
context.res = y
context.done()
});
module.exports = createHandler(app);
context.done();
};
Run Code Online (Sandbox Code Playgroud)
我有function.json:
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"route": "{*segments}"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}
Run Code Online (Sandbox Code Playgroud)
我在azure函数中有上述文件,但是如果我按了api端点,我将无法获得任何输出,只是空白页。我必须使用Express来处理许多其他端点,在Azure函数中是否有任何方法可以处理。
当我使用nodejs本地应用程序设置时,我能够在单个模块中使用express并处理许多api端点,在azure函数中可能吗?或者我必须为每个端点使用不同的功能