Today, I will share a piece of PHP code for merging multiple images into one image. We can use the image merging effect similar to this in image merging, watermarking, and jiugongge. Let's take a look at the example below. Today, I will share a piece of PHP code for merging multiple images into one image. We can use the image merging effect similar to this in image merging, watermarking, and jiugongge. Let's take a look at the example below.
Script ec (2); script
Today, I will share a piece of PHP code for merging multiple images into one image. We can use the image merging effect similar to this in image merging, watermarking, and jiugongge. Let's take a look at the example below.
Example
The Code is as follows: |
|
$ Imgs = array (); $ Imgs [0] = '1.jpg '; $ Imgs [1] = '2.jpg '; $ Imgs [2] = '3.jpg '; $ Imgs [3] = '4.jpg '; $ Target = 'emp.jpg '; // background image $ Target_img = Imagecreatefromjpeg ($ target ); $ Source = array (); Foreach ($ imgs as $ k =>v v ){ $ Source [$ k] ['source'] = Imagecreatefromjpeg ($ v ); $ Source [$ k] ['SIZE'] = getimagesize ($ v ); } // Imagecopy ($ target_img, $ source [0] ['source'], $ source [0] ['SIZE'] [0], $ source [0] ['SIZE'] [1]); // Imagecopy ($ target_img, $ source [1] ['source'], 2, $ source [1] ['SIZE'] [0], $ source [1] ['SIZE'] [1]); $ Num1 = 0; $ Num = 3; // control the number of columns in a row. The value 0 indicates 1, and so on. $ Tmp = 2; $ Tmpy = 2; // spacing between images For ($ I = 0; $ I <4; $ I ++ ){ Imagecopy ($ target_img, $ source [$ I] ['source'], $ tmp, $ tmpy, 0, 0, $ source [$ I] ['SIZE'] [0], $ source [$ I] ['SIZE'] [1]); $ Tmp = $ tmp + $ source [$ I] ['SIZE'] [0]; $ Tmp = $ tmp + 5; If ($ I = $ num ){ $ Tmpy = $ tmpy + $ source [$ I] ['SIZE'] [1]; $ Tmpy = $ tmpy + 5; $ Tmp = 2; $ Num = $ num + 3; } } Imagejpeg(%target_img,'pin.jpg '); ?> |