首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用watermarkjs上传图片前添加水印

问在使用watermarkjs上传图片前添加水印
EN

Stack Overflow用户
提问于 2019-01-31 06:49:00
回答 1查看 1.2K关注 0票数 2

我试着在上传之前用watermark.js在图片上添加水印,但是,我不太明白怎么做。

使用我在uploadFile函数的上传部分得到的代码,图像数据不知何故在水印脚本中丢失了,并且在亚马逊网络服务S3上上传的图像只是一个透明的小方块。

我还添加了预览图像的功能,它工作得很好,可以像预期的那样显示带有水印的图像。

那么,为什么一个函数可以工作,而另一个函数却有问题,我在uploadFile函数中做错了什么?

代码语言:javascript
复制
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);
            });
    };
};
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-01-31 08:13:10

事实证明,我只需将.image(watermark.image.lowerRight())更改为.blob(watermark.image.lowerRight()),一切都正常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54450740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档