Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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
Jquery 输入文件在JCrop中显示实时选定图像_Jquery_Image_Jcrop - Fatal编程技术网

Jquery 输入文件在JCrop中显示实时选定图像

Jquery 输入文件在JCrop中显示实时选定图像,jquery,image,jcrop,Jquery,Image,Jcrop,我正在使用JCrop调整图像大小和裁剪图像 我想添加一个功能,以便用户可以: -选择一个图像文件 -使用jcrop进行编辑 -上传 不改变页面 我可以单独做所有这些,但是当我混合这些的时候,我会有虫子 $('#target').attr('src', e.target.result); $('#target2').attr('src', e.target.result); 现在的问题是,当我更改id“target”主映像的src位置时,它不会显示

我正在使用JCrop调整图像大小和裁剪图像

我想添加一个功能,以便用户可以:

-选择一个图像文件

-使用jcrop进行编辑

-上传 不改变页面

我可以单独做所有这些,但是当我混合这些的时候,我会有虫子

            $('#target').attr('src', e.target.result);
            $('#target2').attr('src', e.target.result);
现在的问题是,当我更改id“target”主映像的src位置时,它不会显示我的新映像。但当我在id为“target2”的预览图像上执行此操作时,它确实会显示我的新图像,并且我可以处理它。(但当我按“裁剪”时不会裁剪新图像)


函数名为cmon(){
jQuery(函数($){
//创建变量(在此范围内)以保存API和图像大小
var jcrop_api,
庞德,
庞迪,
//获取有关预览窗格的一些信息
$preview=$(“#预览窗格”),
$pcnt=$(“#预览窗格.预览容器”),
$pimg=$(“#预览窗格.预览容器img”),
xsize=$pcnt.width(),
ysize=$pcnt.height();
log('init',[xsize,ysize]);
$('#target').Jcrop({
onChange:updatePreview,
onSelect:updatePreview,
onSelect:updateCoords,
aspectRatio:xsize/ysize
},函数(){
//使用API获得真实的图像大小
var bounds=this.getBounds();
boundx=边界[0];
boundy=边界[1];
//将API存储在jcrop_API变量中
jcrop_api=这个;
//将预览移动到jcrop容器中以进行css定位
$preview.appendTo(jcrop_api.ui.holder);
});
函数updatePreview(c)
{
如果(parseInt(c.w)>0)
{
var rx=xsize/c.w;
var ry=ysize/c.h;
$pimg.css({
宽度:数学圆(rx*boundx)+“px”,
高度:数学圆(ry*boundy)+“px”,
marginLeft:“-”+数学四舍五入(rx*c.x)+“px”,
marginTop:“-”+数学圆(ry*c.y)+“px”
});
}
};
});
};
函数updateCoords(c)
{
$('#x').val(c.x);
$('y').val(c.y);
$('w').val(c.w);
$('h').val(c.h);
};
函数checkCoords()
{
if(parseInt($('#w').val())返回true;
警报('请选择作物区域,然后按提交');
返回false;
};
函数readURL(输入){
if(input.files&&input.files[0]){
var reader=new FileReader();
reader.onload=函数(e){
//jcrop_api.setImage(e.target.result);
$('#target').attr('src',e.target.result);
$('#target2').attr('src',e.target.result);
};
reader.readAsDataURL(input.files[0]);
dudecmon();
}
}
/*仅当#预览窗格
已放置在Jcrop小部件中*/
.jcrop支架#预览窗格{
显示:块;
位置:绝对位置;
z指数:2000;
顶部:10px;
右:-280px;
填充:6px;
边框:1pxRGBA(0,0,0,4)实心;
背景色:白色;
-webkit边界半径:6px;
-moz边界半径:6px;
边界半径:6px;
-webkit盒阴影:1px 1px 5px 2px rgba(0,0,0,0.2);
-moz盒阴影:1px1px5px2pRGBA(0,0,0,0.2);
盒影:1px1p5px2pRGBA(0,0,0,0.2);
}
/*Javascript代码将设置裁剪的纵横比
基于缩略图预览大小的区域,
此处指定*/
#预览窗格。预览容器{
宽度:250px;
高度:175px;
溢出:隐藏;
}
您可以使用:

 jcrop_api.setImage('/crop/demo_files/'+$("#btn_change").val());
要更改图片,缺点是这样,您无法正确预览图片

<script type="text/javascript">
  jQuery(function($){
    var jcrop_api;
      $('#btn_change').change(function(){
         $("#fielname").val($("#btn_change").val());
          jcrop_api.setImage('/crop/demo_files/'+$("#btn_change").val());

      })

     $('#croppic').click(function(){

      if(checkCoords()){
       var data =  { x: $('#x').val(), y: $('#y').val(),w: $('#w').val(), h: $('#h').val(),fielname:$("#fielname").val() };

        $.post("http://localhost/crop/index.php/welcome/croppic",data,
        function(backdata){
          if(backdata=="success"){
                jcrop_api.release();
                $('#cropmessage').html("<font color=red>thumb pic made please select another one</font>").delay(1000).fadeOut();;
            }
            else
            {
                $('#cropmessage').html("<font color=black>error in process </font>");
            }
        });
        }

      });
      // Create variables (in this scope) to hold the API and image size
    var jcrop_api,
        boundx,
        boundy;

    $('#target').Jcrop({
      onSelect: updateCoords,
      aspectRatio: xsize / ysize
    },function(){
      // Use the API to get the real image size
      var bounds = this.getBounds();
      boundx = bounds[0];
      boundy = bounds[1];
      // Store the API in the jcrop_api variable
      jcrop_api = this;


    });


   function updateCoords(c)
  {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#w').val(c.w);
    $('#h').val(c.h);
  };


    function checkCoords()
    {
        if (parseInt($('#w').val())) return true;
        alert('Please select a crop region then press submit.');
        return false;
    };



  });

</script>

jQuery(函数($){
var jcrop_api;
$('btn_change').change(函数(){
$(“#fielname”).val($(“#btn#u change”).val();
jcrop_api.setImage('/crop/demo_files/'+$(“#btn_change”).val();
})
$('#cropic')。单击(函数(){
if(checkCoords()){
var data={x:$('#x').val(),y:$('#y').val(),w:$('#w').val(),h:$('#h').val(),fielname:$('#fielname').val();
$.post(”http://localhost/crop/index.php/welcome/croppic“、数据、,
函数(后台数据){
if(backdata==“success”){
jcrop_api.release();
$('#cropmessage').html(“拇指图片制作完毕,请选择另一张”).delay(1000).fadeOut();;
}
其他的
{
$('#cropmessage').html(“处理中的错误”);
}
});
}
});
//创建变量(在此范围内)以保存API和图像大小
var jcrop_api,
庞德,
庞迪;
$('#target').Jcrop({
onSelect:updateCoords,
aspectRatio:xsize/ysize
},函数(){
//使用API获得真实的图像大小
var bounds=this.getBounds();
boundx=边界[0];
boundy=边界[1];
//将API存储在jcrop_API变量中
jcrop_api=这个;
});
函数updateCoords(c)
{
$('#x').val(c.x);
$('y').val(c.y);
$('w').val(c.w);
$('h').val(c.h);
};
函数checkCoords()
{
if(parseInt($('#w').val())返回true;
警报('请选择作物区域,然后按提交');
返回false;
};
});

能否显示您使用该功能的链接?不确定您问了什么,但这是api?
<script type="text/javascript">
  jQuery(function($){
    var jcrop_api;
      $('#btn_change').change(function(){
         $("#fielname").val($("#btn_change").val());
          jcrop_api.setImage('/crop/demo_files/'+$("#btn_change").val());

      })

     $('#croppic').click(function(){

      if(checkCoords()){
       var data =  { x: $('#x').val(), y: $('#y').val(),w: $('#w').val(), h: $('#h').val(),fielname:$("#fielname").val() };

        $.post("http://localhost/crop/index.php/welcome/croppic",data,
        function(backdata){
          if(backdata=="success"){
                jcrop_api.release();
                $('#cropmessage').html("<font color=red>thumb pic made please select another one</font>").delay(1000).fadeOut();;
            }
            else
            {
                $('#cropmessage').html("<font color=black>error in process </font>");
            }
        });
        }

      });
      // Create variables (in this scope) to hold the API and image size
    var jcrop_api,
        boundx,
        boundy;

    $('#target').Jcrop({
      onSelect: updateCoords,
      aspectRatio: xsize / ysize
    },function(){
      // Use the API to get the real image size
      var bounds = this.getBounds();
      boundx = bounds[0];
      boundy = bounds[1];
      // Store the API in the jcrop_api variable
      jcrop_api = this;


    });


   function updateCoords(c)
  {
    $('#x').val(c.x);
    $('#y').val(c.y);
    $('#w').val(c.w);
    $('#h').val(c.h);
  };


    function checkCoords()
    {
        if (parseInt($('#w').val())) return true;
        alert('Please select a crop region then press submit.');
        return false;
    };



  });

</script>