在PHP中裁剪功能出错

时间:2018-04-05 10:45:01

标签: javascript php crop jcrop

这是我剪裁图像功能的完整代码。它有效。但它错误地裁剪。我无法找出错误。功能正常,但错误。 When I crop the image我的裁剪照片My cropped image

<img style="padding-top:5%;" src="<?php echo $rowquerycat2[KEY_NAME]; ?>" id="rrr" alt="" class="img-responsive" /></div>
        <form style="display: none;" id="croptype">
                        <input type="text" id="x" name="x" />
                        <input type="text" id="y" name="y" />
                        <input type="text" id="w" name="w" />
                        <input type="text" id="h" name="h" />
          <input type="button" value="Crop Image" id="crop_btn" onclick="crop_photo()" />
                    </form>
          <div id="photo_container"> </div>

通过ajax函数传递坐标值的javascript代码

    function crop_photo() {
  //alert("hi");
    var x_ = $('#x').val();
    var y_ = $('#y').val();
   var w_ = $('#w').val();
  var h_ = $('#h').val();

   $.ajax({
        url: 'crop_photo.php',
        type: 'POST',
        data: {x:x_, y:y_, w:w_, h:h_, targ_w:TARGET_W, targ_h:TARGET_H},
        success:function(data){
          alert("sucess");
         $('#photo_container').html(data);
        }
    });
}

crop_photo.php。

 <?php
    $targ_w = $_POST['w'];
     $targ_h = $_POST['h'];
        $jpeg_quality = 90;
        $src = $_POST['photo_url'];
        $src1 = basename($src);
        $ext = pathinfo($src1, PATHINFO_EXTENSION);
       if($ext == 'jpg'){
         $imagesrori = imagecreatefromjpeg($src);

         }
       //$img_r = imagecreatefromjpeg($src);
         $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

        imagecopyresampled($dst_r,$imagesrori,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']);

        // create the physical photo

        imagejpeg($dst_r, 'cropimage/' . $src1);

        echo '<img src="'.'cropimage/'. $src1.'?'.time().'">';
        exit;
        ?>

0 个答案:

没有答案