This article mainly introduces the method of merging multiple pictures into one in PHP. Friends who are interested can refer to it. I hope it will be helpful to everyone.
The example is as follows:
$pic_path ) { $kk = $k + 1; if ( in_array($kk, $lineArr) ) { $start_x = $line_x; $start_y = $start_y + $pic_h + $space_y; } $pathInfo = pathinfo($pic_path); switch( strtolower($pathInfo['extension']) ) { case 'jpg': case 'jpeg': $imagecreatefromjpeg = 'imagecreatefromjpeg'; break; case 'png': $imagecreatefromjpeg = 'imagecreatefrompng'; break; case 'gif': default: $imagecreatefromjpeg = 'imagecreatefromstring'; $pic_path = file_get_contents($pic_path); break; } $resource = $imagecreatefromjpeg($pic_path); // $start_x,$start_y copy图片在背景中的位置 // 0,0 被copy图片的位置 // $pic_w,$pic_h copy后的高度和宽度 imagecopyresized($background,$resource,$start_x,$start_y,0,0,$pic_w,$pic_h,imagesx($resource),imagesy($resource)); // 最后两个参数为原始图片宽度和高度,倒数两个参数为copy时的图片宽度和高度 $start_x = $start_x + $pic_w + $space_x; } header("Content-type: image/jpg"); imagejpeg($background); imagegif($background, "./hero_gam.png"); ?>
Related recommendations:
php realizes image merging in WeChat-Nine Palaces Pictures
php Merge multiple pictures into one, how to avoid
How to combine multiple pictures into one pdf file using Python combined with ImageMagick
The above is the detailed content of Methods and cases for merging multiple pictures into one in PHP. For more information, please follow other related articles on the PHP Chinese website!