450x450 px のソース画像があります。そして、PHPを使用して、それぞれ150x150の9ピースにトリミングしたいと考えています。
次のコードを使用しています。
9 枚の画像を取得していますが、トリミングが適切ではありません。スクリーン ショットは次のとおりです。
最後の 1 つは、使用しているソース イメージです。
これが私のコードです。
<?php
$targ_w = $targ_h = 150;
$jpeg_quality = 25;
$src = "puzzleimages/puzzle2.jpg";
$y = 0;
$y2 = 150;
$x = 0;
$x2 = 150;
$i = 3;
$name = 0;
while( $i-- ){
$j = 3;
while( $j-- ){
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,$targ_w,$targ_h,$x2,$y2);
//header('Content-type: image/jpeg');
imagejpeg($dst_r,'puzzleimages/'.++$name.'.jpg', $jpeg_quality);
$x += 150;
$x2 += 150;
}
$y += 150;
$y2 += 150;
$x = 0;
$x2 = 150;
}
?>
誰が何が間違っているのか提案できますか?