Method One: Compositeimages
/** * Function: Compositing picture * @param string $output _url picture Save path * @param string $img _type picture Save type * @param integral $line Display the number of pictures per line * @param array $logo _info each image to be synthesized (requires all dimensions unified) * @param array $img _list The absolute path of the image to be synthesized * * @return void */Public function Generate ($output _url, $img _type, $line _num, $logo _info, $img _list=array ()) {//Calculate how many lines of the picture are $lines = Ceil (count ($img _list)/$line _num); $BG _width = ($logo _info[' width ') + $logo _info[' line_width ']) * $line _num; $BG _height = ($logo _info[' height ') + $logo _info[' line_height ']) * $lines; Build Canvas $canvas = new Imagick (); $canvas->newimage ($bg _width, $bg _height, ' White '); $canvas->setimageformat ($img _type); $i = $j = 0; foreach ($img _list as $item) {$im = new Imagick ($item); $x = $logo _info[' line_width ']*2 + $i * $logo _info[' width ']; $y = $logo _info[' line_height ']*2 + $j * $logo_info[' height ']; $canvas->compositeimage ($im, GetImage (), Imagick::composite_over, $x, $y); $canvas-Compositeimage ($im, $im->getimagecompose (), $x, $y); if (($i + 1)% $line _num = = = 0) {$i = 0; $j + +; } else {$i + +; }//Unset ($IM); $im-Destroy (); } $canvas->writeimage ($output _url); Destroyed Objects $canvas, destroy (); }
Method Two: Combineimages
/** * Function: Compositing picture * @param string $output _url picture Save path * @param string $img _type picture Save type * @param integral $line Display the number of pictures per line * @param array $logo _info each image to be synthesized (requires all dimensions unified) * @param array $img _list The absolute path of the image to be synthesized * * @return void */Public function Generate ($output _url, $img _type, $line _num, $logo _info, $img _list=array ()) {//Calculate how many lines of the picture are $lines = Ceil (count ($img _list)/$line _num); $BG _width = ($logo _info[' width ') + $logo _info[' line_width ']) * $line _num; $BG _height = ($logo _info[' height ') + $logo _info[' line_height ']) * $lines; Build canvas $canvas = null; $canvas = new Imagick (); $canvas-NewImage ($bg _width, $bg _height, ' White '); $i = $j = 0; foreach ($img _list as $item) {$im = null; $im = new Imagick ($item); $canvas-Readimage ($item); $canvas-AddImage ($im); $im, Clear (); $im-Destroy (); }//$canvas-flattenimages (); Combineimages, $canvas (Imagick::channel_all); $canvas-Writeimage ($output _url); Destroy Object $canvas Clear (); $canvas-Destroy (); }
Personally think method two more efficient