【发布时间】:2021-05-09 12:01:22
【问题描述】:
我在我的 express.js 服务器上使用 mergeImages,但我收到“ReferenceError:未定义窗口”的错误。我不知道它在说什么。即使我没有在我的代码中使用窗口词。 请检查我的 server.js 代码。在代码的末尾我有 mergeimage 功能。
const express = require('express');
const app = express();
const fs = require('fs');
const mergeImages = require('merge-images');
const bodyParser = require('body-parser');
const multer = require('multer');
const { response } = require('express');
const cors = require('cors');
app.use(cors());
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
app.get('/', (req,res) => {
res.send('this is express!');
})
app.listen(8000, (err) =>{
if(err) console.log(err);
console.log('Server Started please listen to port: 8000');
})
app.get('/get-image', function(req,res,next){
const pixel_base_value = 1.31;
const top_margin = 5;
const left_margin = 3;
var photo_frame = [];
for(var j = 1; j <= req.query.row; j++){
var total_width_check = 0;
var total_height_check = 0;
for(var k= 1; k <= req.query.col; k++){
var height_cal = req.query.photo_height*pixel_base_value;
var width_cal = req.query.photo_width*pixel_base_value;
if(j !== 1){
var top1 = top_margin + height_cal + 3;
}else{
top1 = top_margin;
}
if(k !== 1){
var left1 = (width_cal * (k-1) + (left_margin * k));
}else{
left1 = left_margin;
}
total_width_check = total_width_check + req.query.photo_width*pixel_base_value + left_margin;
total_height_check = total_height_check + req.query.photo_height*pixel_base_value + top_margin;
if(total_width_check >= req.query.board_width*pixel_base_value-3 && total_height_check >= req.query.board_height*pixel_base_value-3){
}else{
photo_frame.push({src:'http://localhost:8000/image/'+ req.query.img_name +'', x: left1, y: top1, width: width_cal, height: height_cal});
}
}
total_width_check = 0;
}
//check photo_frame is a valid Array
mergeImages(photo_frame).then((b64) =>{ //add options here for canvas
console.log(b64)
},(error) =>{
console.log(error);
} );
return res.end('done');
})
请帮忙!
谢谢!
【问题讨论】:
标签: javascript node.js image express image-processing