Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何修复getimagedata操作不安全_Javascript_Html_Canvas - Fatal编程技术网

Javascript 如何修复getimagedata操作不安全

Javascript 如何修复getimagedata操作不安全,javascript,html,canvas,Javascript,Html,Canvas,使用相当基本的代码 HTML imgSrc?>; imgSrc是不在同一域上的URL。该站点位于本地主机上,映像位于另一个站点上,并且是https 如果我删除image.crossOrigin=“匿名”,图像加载,但我得到了安全错误。如果我放回交叉原点,图像根本不会加载,加载处理程序永远不会启动 将图像移动到为页面提供服务的服务器不是一个现实的选择,因为图像将被卡在那里,直到其他服务或进程将其清除 我错过了什么 谢谢我可以用一些卷曲脊椎的代码来修复这个问题 在我的php中,我做到了这一点 va

使用相当基本的代码

HTML

imgSrc?>;
imgSrc是不在同一域上的URL。该站点位于本地主机上,映像位于另一个站点上,并且是https

如果我删除
image.crossOrigin=“匿名”,图像加载,但我得到了安全错误。如果我放回交叉原点,图像根本不会加载,加载处理程序永远不会启动

将图像移动到为页面提供服务的服务器不是一个现实的选择,因为图像将被卡在那里,直到其他服务或进程将其清除

我错过了什么


谢谢

我可以用一些卷曲脊椎的代码来修复这个问题

在我的php中,我做到了这一点

var image = document.getElementById("img");

image.crossOrigin = "anonymous";
image.addEventListener('load', function (event) {
    alert("here");         

    orgImg.width = this.naturalWidth;
    orgImg.height = this.naturalHeight;
    orgImg.getContext("2d").drawImage(this, 0, 0);           

    //etc
    orgImg.getContext("2d").getImageData(0, 0, orgImg.width, orgImg.height) //security error
}, {once: true});
image.src = '<?= $this->imgSrc ?>';
这样就不会使用原始图像,而是发送一个epic字符串,这不会导致安全问题。 然后为了减轻内存,我添加了
image.src=“”至加载事件结束

        $imgSrc= $this->_request->getParam('imgSrc', ''); //URL of image
        if (!empty($imgSrc)) {
            $imgSrc = file_get_contents($imgSrc); //naughty variable reuse
            $imgSrc = 'data:image/x-icon;base64,' . base64_encode($imgSrc);
        }
var image=document.getElementById(“img”);
image.addEventListener('load',函数(事件){
警报(“此处”);
orgImg.WITH=此.NATURALWITH;
组织高度=这个自然高度;
orgImg.getContext(“2d”).drawImage(this,0,0);
image.src=”“;//从内存中清除大量字符串
//等
orgImg.getContext(“2d”).getImageData(0,0,orgImg.width,orgImg.height)//安全性错误
},{once:true});
image.src='';
这个页面永远不会被手机访问,所以可以暂时使用疯狂内存。但如果有人有一个更好的解决方案,那就更好了


谢谢

我可以用一些卷曲脊椎的代码来修复这个问题

在我的php中,我做到了这一点

var image = document.getElementById("img");

image.crossOrigin = "anonymous";
image.addEventListener('load', function (event) {
    alert("here");         

    orgImg.width = this.naturalWidth;
    orgImg.height = this.naturalHeight;
    orgImg.getContext("2d").drawImage(this, 0, 0);           

    //etc
    orgImg.getContext("2d").getImageData(0, 0, orgImg.width, orgImg.height) //security error
}, {once: true});
image.src = '<?= $this->imgSrc ?>';
这样就不会使用原始图像,而是发送一个epic字符串,这不会导致安全问题。 然后为了减轻内存,我添加了
image.src=“”至加载事件结束

        $imgSrc= $this->_request->getParam('imgSrc', ''); //URL of image
        if (!empty($imgSrc)) {
            $imgSrc = file_get_contents($imgSrc); //naughty variable reuse
            $imgSrc = 'data:image/x-icon;base64,' . base64_encode($imgSrc);
        }
var image=document.getElementById(“img”);
image.addEventListener('load',函数(事件){
警报(“此处”);
orgImg.WITH=此.NATURALWITH;
组织高度=这个自然高度;
orgImg.getContext(“2d”).drawImage(this,0,0);
image.src=”“;//从内存中清除大量字符串
//等
orgImg.getContext(“2d”).getImageData(0,0,orgImg.width,orgImg.height)//安全性错误
},{once:true});
image.src='';
这个页面永远不会被手机访问,所以可以暂时使用疯狂内存。但如果有人有一个更好的解决方案,那就更好了


谢谢

可能重复我在原始问题中遵循了这些说明。不幸的是,设置交叉原点不起作用,移动图像也不太可能。可能重复我在最初的问题中遵循了这些说明。不幸的是,设置交叉原点不起作用,移动图像也不太可能。