Example of merging multiple images in PHP-PHP source code

Source: Internet
Author: User
Tags imagecopy
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 ');
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.