1 function combineimage ($head _img, $middle _img, $footer _img, $save _path) {2 $source _w = n; 3 $source _h = 1142; 4 Take the head picture size 5 $head _size = getimagesize ($head _img); 6 $head _height = $head _size[' 1 '); 7 $head _width = $head _size[' 0 '); 8 $head _start_x = Floor (($source _w-$head _width)/2)//Head Start position 9//Take the middle picture size $midd _size = getimagesize ($middle _im g) One $midd _height = $midd _size[' 1 '];12 $midd _width = $midd _size[' 0 '];13 $midd _start_y = $head _height-15;//Middle Open Start y coordinate, because the head of the picture at the bottom of the blank, so minus 1514 $midd _start_x = Floor (($source _w-$midd _width)/2); 15 16//Take the bottom picture size: $foot _size = GetImageSize ($footer _img) $foot _height = $foot _size[1];19 $foot _width = $foot _size[0];20 $foot _start_x = f Loor (($source _w-$foot _width)/2);//Bottom picture x coordinate $foot _start_y = $source _h-$foot _height;//bottom Picture y-coordinate $head = Imag Ecreatefrompng ($head _img), $middle = Imagecreatefrompng ($middle _img); $footer = Imagecreatefrompng ($footer _img ); 26 27 $BG _img = Imagecreatetruecolor ($source _w, $source _h);//generate background picture $color = Imagecolorallocate ($bg _img, 255, 255, 255); Set white background Imagefill ($BG _img, 0, 0, $color),///background color filled with imagecolortransparent ($BG _img, $color);//Transparent Imagecopyr Esampled ($BG _img, $head, $head _start_x,0,0,0, $head _width, $head _height, $head _width, $head _height); 32 Imagecopyresampled ($BG _img, $middle, $midd _start_x, $midd _start_y,0,0, $midd _width, $midd _height, $midd _width, $midd _ height); imagecopyresampled ($bg _img, $footer, $foot _start_x, $foot _start_y,0,0, $foot _width, $foot _height, $foot _ width, $foot _height), Imagepng ($bg _img, $save _path),}37 $head = dirname (__file__). ' /public/images/head.png '; $midd = DirName (__file__). ' /public/images/midd1.png '; $foot = DirName (__file__). ' /public/images/foot1.png '; $save _path = DirName (__file__). " /public/images/testcomblie.png combineimage ($head, $midd, $foot, $save _path);
PHP merge pictures (go)