我正在尝试裁剪我的图像,但是当我这样做时,它会显示为正确的尺寸,但全部为黑色。我已经尝试了至少十几个不同的脚本,但我似乎无法让它们中的任何一个工作:(
哦,旋转脚本工作正常,所有的回声都只是用于测试,将被删除:D
<?php
$staffID = $_POST['u'];
$actCode = $_POST['a'];
$tempAvatar = $_POST['tempAvatar'];
$x1 = $_POST['x'];
$y1 = $_POST['y'];
$wH = $_POST['w'];
$scale = $_POST['scale'];
$angle = $_POST['angle'];
$destFolder = "../../../avatars/";
$imagePath = "tempAvatars/".$tempAvatar.".jpg";
$imagePathRot = "tempAvatars/".$tempAvatar."ROTATED.jpg";
$imagePathCropped= "tempAvatars/".$tempAvatar."CROPPED.jpg";
echo 'X1: '.$x1.'<br>Y1: '.$y1.'<br>Width/Height: '.$wH.'<br>Angle: '.$angle;
if ($angle != 0) {
$source = imagecreatefromjpeg($imagePath) or notfound();
$rotate = imagerotate($source,$angle,0);
imagejpeg($rotate, $imagePathRot);
$imagePath = $imagePathRot;
}
echo '<br>X2: '.$x2.'<br>Y2: '.$y2;
$targ_w = 300;
$jpeg_quality = 90;
$img_r = imagecreatefromjpeg($imagePath);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_w );
imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'],
$targ_w,$targ_h,$_POST['w'],$_POST['w']);
imagejpeg($dst_r, $imagePathCropped, $jpeg_quality);
echo '<br><img src="'.$imagePathCropped.'">';
?>