I got to compositing multiple images on to canvas, but the final images' filename are inconsistent with the original images' filename.
Code: Select all
<?php
// Get the image
$mgk_wnd1 = NewMagickWand();
MagickReadImages($mgk_wnd1, $img_name = glob("*.jpg"));
// Get number of images stored in the wand
$num_img = MagickGetNumberImages($mgk_wnd1);
// Create a white 640x480 jpeg canvas
$mgk_wnd2 = NewMagickWand();
MagickNewImage($mgk_wnd2, 640, 480, "white");
MagickSetformat($mgk_wnd2, "jpg");
// Set offsets x and y
$x_offset = 150;
$y_offset = 100;
for ($i = 0; $i < $num_img; $i++) {
if (MagickGetImageHeight($mgk_wnd1) != 480 && MagickGetImageWidth($mgk_wnd1) != 640) {
echo $img_name[$i] . "<br/>";
// Composite both original image and the canvas
MagickCompositeImage($mgk_wnd2, $mgk_wnd1, MW_OverCompositeOp, $x_offset, $y_offset);
// Write the image to a file
MagickWriteImages($mgk_wnd2, "images/$img_name[$i]", TRUE);
MagickRemoveImage($mgk_wnd1);
}
}
// Enhance image
//MagickEnhanceImage($mgk_wnd2);
// Clean up wands
if($mgk_wnd1 && $mgk_wnd2) {
$mgk_wnd1 = DestroyMagickWand($mgk_wnd1);
$mgk_wnd2 = DestroyMagickWand($mgk_wnd2);
}
?>