Jquery プラグイン ImgAreaSelect を PHP 5.3.9 と GD 2.0.34 で使用しています。
プラグインのいくつかの例に従って、画像の選択を開始してから選択が終了するまでの X 値と Y 値を提供するフォームを追加しました。
値を正しく受け取っているため、これは問題ありませんが、画像をトリミングすることはできません。いくつかの例/チュートリアルに従いましたが、常に失敗しました。
ここに私のPHPコードがあります:
$x1 = $_POST['x1']; //this one gives me the point where start to crop
$x2 = $_POST['x2']; //the end of X axis
$y1 = $_POST['y1']; //same for Y1 and Y2
$y2 = $_POST['y2'];
$w = $x2 - $x1; //getting the width for the new image
$h = $y2 - $y1; //getting the height for the new image
$src_img = "path/image";
$format = end(explode(".", $src_img)); //taking the image format (jpg, png, gif)
$size = getimagesize($src_img);
switch($format) {
case "jpg":
$copy = imagecreatefromjpeg($src_img);
$new = ImageCreateTrueColor($w, $h);
imagecopyresampled($new, $copy, 0, 0, $x1, $y1, $w, $h, $size[0], $size[1]);
header('Content-type: image/jpeg');
imagejpeg($new);
break;
}
何か問題があるかどうか知りたいです(おそらく)。
ご協力いただきありがとうございます。