0

サンプルコードがあります:

$image_1 = "image_1.jpg";

画像1

$image_2 = "image_2.jpg";

画像2

コードphpは2つの画像をマージします:

function merge($filename_x, $filename_y, $filename_result) {
    // Get dimensions for specified images

    list($width_x, $height_x) = getimagesize($filename_x);
    list($width_y, $height_y) = getimagesize($filename_y);


    // Create new image with desired dimensions
    $image = imagecreatetruecolor($width_x + $width_y, $height_x);

    // Load images and then copy to destination image
    $image_x = imagecreatefromjpeg($filename_x);
    $image_y = imagecreatefromjpeg($filename_y);

    imagecopy($image, $image_x, 0, 0, 0, 0, $width_x, $height_x);
    imagecopy($image, $image_y, $width_x, 0, 0, 0, $width_y, $height_y);

    // Save the resulting image to disk (as JPEG)
    imagejpeg($image, $filename_result);

    // Clean up
    imagedestroy($image);
    imagedestroy($image_x);
    imagedestroy($image_y);
}

$image_1 = 'image_1.jpg';
$image_2 = 'image_2.jpg';
merge($image_1, $image_2, 'merged.jpg');

結果は次のとおりです。

合併した

image_2でマージンセンターにimage_1を修正する方法

真実

4

1 に答える 1

0

imagecopy() の 3 番目のパラメーター (画像の位置の x 値) を、大きい画像の幅の 1/2 - 小さい画像の幅の 1/2 に変更してみてください。

于 2013-08-30T03:52:53.557 に答える