imagecopyresampled()
$src_image
位置で幅と高さの長方形の領域を取り、位置で幅$src_w
と高さの$src_h
長方形の領域($src_x, $src_y)
に配置します。$dst_image
$dst_w
$dst_h
($dst_x, $dst_y)
ソースとデスティネーションの座標と幅と高さが異なる場合は、画像フラグメントの適切な拡大または縮小が実行されます。座標は左上隅を参照しています。
この機能は、同じ画像内の領域をコピーするために使用できます。ただし、リージョンが重複している場合、結果は予測できません。
- 編集 -
$src_w
とがそれぞれと$src_h
よりも小さい場合は、親指の画像がズームインされます。それ以外の場合は、ズームアウトされます。$dst_w
$dst_h
<?php
$dst_x = 0; // X-coordinate of destination point
$dst_y = 0; // Y-coordinate of destination point
$src_x = 100; // Crop Start X position in original image
$src_y = 100; // Crop Srart Y position in original image
$dst_w = 160; // Thumb width
$dst_h = 120; // Thumb height
$src_w = 260; // Crop end X position in original image
$src_h = 220; // Crop end Y position in original image
// Creating an image with true colors having thumb dimensions (to merge with the original image)
$dst_image = imagecreatetruecolor($dst_w, $dst_h);
// Get original image
$src_image = imagecreatefromjpeg('images/source.jpg');
// Cropping
imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// Saving
imagejpeg($dst_image, 'images/crop.jpg');
?>