我试着在上传之前用watermark.js在图片上添加水印,但是,我不太明白怎么做。
使用我在uploadFile函数的上传部分得到的代码,图像数据不知何故在水印脚本中丢失了,并且在亚马逊网络服务S3上上传的图像只是一个透明的小方块。
我还添加了预览图像的功能,它工作得很好,可以像预期的那样显示带有水印的图像。
那么,为什么一个函数可以工作,而另一个函数却有问题,我在uploadFile函数中做错了什么?
const uploadFile = file => {
axios.get(`/api/imageUpload/${file.type}`)
.then(uploadConfig => {
watermark([file, '../static/images/watermark_white.png'])
.image(watermark.image.lowerRight())
.then(img => {
axios.put(uploadConfig.data.url, img, {
headers: {
"Content-Type": file.type
},
}).then(() => {
props.onUpload(uploadConfig.data.key);
});
});
});
};
const previewFile = file => {
if (!isImage(file)) {
return;
}
let reader = new FileReader();
reader.readAsDataURL(file);
reader.onloadend = () => {
let img = document.createElement("img");
img.src = reader.result;
watermark([img, '../static/images/watermark_white.png'])
.image(watermark.image.lowerRight())
.then(function (img) {
document.getElementById("gallery").appendChild(img);
});
};
};发布于 2019-01-31 08:13:10
事实证明,我只需将.image(watermark.image.lowerRight())更改为.blob(watermark.image.lowerRight()),一切都正常。
https://stackoverflow.com/questions/54450740
复制相似问题