2014-11-19 3 views
1

jcrop 플러그인을 사용하여 여러 이미지를 자르려고합니다. 이 플러그인은 단일 이미지 자르기 작업하지만 루프에서 개별적으로 여러 이미지를 자르는 방법을 모릅니다.jcrop을 사용하여 여러 이미지 자르기

<?php 

    $id=$_GET['id']; 
    $query_image=mysql_query("SELECT * FROM tbl_images WHERE `id`='$id'"); 

    $j=0; 
    while($rowq=mysql_fetch_assoc($query_image)) 
    { 
    $image_source = $rowq['image']; 

?> 

    <div> 
    <img src="../image_files/<?php echo $image_source;?>" width="550px" id="cropbox_<?php echo $j;?>" /> 

     <form action="crop_image.php?id=<?php echo $id;?>" method="post" onsubmit="return checkCoords()"> 
      <input type="text" id="x" name="x" value="" /> 
      <input type="text" id="y" name="y" value=""/> 
      <input type="text" id="w" name="w" value=""/> 
      <input type="text" id="h" name="h" value=""/> 

      <input type="submit" value="crop"> 
      <input type="reset" value="cancel"> 
     </form> 
    </div> 

<?php 
    $j++; 
} 
    $count = $j; 
?> 

다음과

<script type="text/javascript"> 

    var i; 
    var count = "<?php echo $count;?>"; 

    $(function(){ 
     for(i=0; i<count;i++) 
     { 
     $('#cropbox_'+i).Jcrop({  
     aspectRatio: 0, 
     onSelect: updateCoords 
     }); 
    } 
    });  

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

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

</script> 

하지만 함수 updateCoords (c) 반환하지 좌표 값을 다음과 같이 jcrop 함수는 나의 ​​PHP 파일이다. 이 코드에 대한 제안 사항이 있으시면 언제든지 도와주세요. 미리 감사드립니다. 이미지 양식

+0

처음 u로 숨겨진 입력 필드 nique id, while 루프에 있기 때문에 양식이 같은 내용으로 반복됩니다. – shaN

답변

1

updateCoords (C) 기능

<form action="crop_image.php?id=<?php echo $id;?>" method="post" onsubmit="return checkCoords('<?php echo $j;?>')"> 
     <input type="text" id="x_<?php echo $j;?>" name="x" value="" /> 
     <input type="text" id="y_<?php echo $j;?>" name="y" value=""/> 
     <input type="text" id="w_<?php echo $j;?>" name="w" value=""/> 
     <input type="text" id="h_<?php echo $j;?>" name="h" value=""/> 

     <input type="submit" value="crop"> 
     <input type="reset" value="cancel"> 
    </form> 

function updateCoords(c) 
    { 
    for(i=0; i<count;i++) 
    { 
     var x = $('#x_'+i).val(c.x); 
     var y = $('#y_'+i).val(c.y); 
     $('#w_'+i).val(c.w); 
     $('#h_'+i).val(c.h); 
    } 
    }; 

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

하이 sujan 시도가 제공해야 할 모든이

관련 문제