我想将几张图像合并为一张。我在下面有这个数组。
$products_settings - 数组:
(
[0] => Array
(
[product_left] => 368
[product_top] => 317
[product_width] => 67.0
[product_height] => 85.0
[product_file] => /whateverfile1.jpg
)
[1] => Array
(
[product_left] => 569
[product_top] => 459
[product_width] => 67.0
[product_height] => 85.0
[product_file] => /whateverfile2.jpg
)
[2] => Array
(
[product_left] => 710
[product_top] => 359
[product_width] => 67.0
[product_height] => 85.0
[product_file] => /whateverfile3.jpg
)
)
我试过这个:
<?php
header('Content-Type: image/jpeg');
foreach($products_settings as &$ps) {
//Original-product/image-file
$filename = $ps['product_file'];
list($source_width, $source_height) = getimagesize($filename);
$source_image = imagecreatefromjpeg($filename);
//Destination image (as large as outfit-area-canvas)
$dest_image = imagecreatetruecolor(intval($canvas_settings['width_canvas']), intval($canvas_settings['height_canvas']));
$dest_width = intval($ps['product_width']);
$dest_height = intval($ps['product_height']);
$dest_x = intval($ps['product_left']);
$dest_y = intval($ps['product_top']);
//Resize source-image to new width and height and then copy from source to destination
imagecopyresized($dest_image, $source_image, $dest_x, $dest_y, 0, 0, $dest_width, $dest_height, $source_width, $source_height);
imagejpeg($dest_image, 'dummy.jpg');
}
?>
只有数组中的最后一个图像(在这种情况下为whateverfile3.jpg)$products_settings
被合并到文件dummy.jpg中,但我想将所有三个产品合并到文件dummy.jpg中。我怎么能做到这一点?请给我一些指点!