【发布时间】:2016-12-29 13:52:32
【问题描述】:
基本上,我创建的 png 始终具有 300 h 150 的尺寸,我想要更大的尺寸。这是我尝试做的。
// this was my last trial I tried canging the width in the canvas tag
var newCanvas = $("<canvas/>", {"class" : "pic", "width" : "1000px", "height" :"300px"}).width(1000).height(500)
// $(".mainContent").prepend(newCanvas);
// var canvasData = dataGatherer();
var canvas = newCanvas[0];
console.log(canvas)
var ctx = canvas.getContext("2d");
ctx.font = "30px Arial"
console.log("datum---TEST--", datum)
ctx.fillText(datum.reviewText, 10, 50)
console.log(canvas.toDataURL())
datum.img = canvas.toDataURL();
服务器中的某个地方:
if(req.body.img){
var img = req.body.img;
data = img.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, "base64");
fs.unlink(__dirname + "/../public/another.png", function(){
fs.writeFile(__dirname + "/../public/another.png", buf, {flag : "w"},function(){
console.log("++++writen to file+++++")
})
});
}
【问题讨论】: