jcrop黑色图像jpeg

时间:2017-06-21 17:14:49

标签: image jcrop

您好我用jcrop制作了一个裁剪脚本。一切都运行正常但是当我保存jpeg(它是一个jpeg)比裁剪图像只是黑色。我在互联网上搜索了很多并尝试了很多解决方法,但我无法找到解决问题的方法。

请帮忙......

<!doctype html>
<html lang="de">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>VM</title>
        <link href="css/fontello.css" rel="stylesheet">
        <link href="assets/jcrop/css/Jcrop.css" rel="stylesheet"> 
        <link href="css/style.css" rel="stylesheet">
        <script src="js/jquery-3.2.1.min.js"></script>
        <script src="assets/jcrop/js/Jcrop.min.js"></script>
        <script>

        $(document).ready(function(){
                $('#cropimage').Jcrop({
                        aspectRatio: 573 / 797,
                        boxWidth: 450, 
                        onSelect: function(coords){    $('#cropimagefield').val(coords.x + ':' + coords.y + ':' + coords.w + ':' + coords.h);
                            }
                    });
            });

        </script>

    </head>
  <body>
 <?php 
 // Post von Bild
  $src = "bilder/Körber_6_2005_von_2017.jpg";

  if(isset($_POST["speichern"])) {


  $coords = list($x, $y, $w, $h) = explode(':', $_POST["cropimage"]);
   $bildbreite = getimagesize($src);
  if($bildbreite[0] > 459) {
        $factor = $bildbreite[0] / 500;
        $x = round($x * $factor);
        $y = round($y * $factor);
        $w = round($w * $factor);
        $h = round($h * $factor);
 } 


 // Konstanten
  $targ_w = 1146;
  $targ_h = 1594;
  $jpeg_quality = 90;

 echo $x."<br>";
 echo $y."<br>";
 echo $w."<br>";
 echo $h."<br>";


 // Bild beschneiden
    $img_r = imagecreatefromjpeg($src);
    $dst_r = ImageCreateTrueColor($targ_w, $targ_h);
    imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
  header('Content-type: image/jpeg');
  imagejpeg($dst_r, "bilder/martin_neu.jpg");

  }
?>

  <form action="crop.php" method="post">
    <img alt="Bild" <?php echo 'src="'.$src.'"'; ?> id="cropimage" style="width: 500px;" />
    <input type="hidden" id="cropimagefield" name="cropimage" />
    <input type="submit" name="speichern" value="Speichern" />
</form>

  </body>
  </html>

0 个答案:

没有答案