Php merge pictures, _ PHP Tutorial

Source: Internet
Author: User
Php merge images ,. Php merge images. several images need to be merged in the project. for example, the code is as follows: 1 functioncombineImage ($ head_img php merge images,

You need to combine several images in a project, such

These images are merged by three pictures: head, body, and leg.

The code is as follows:

1 function combineImage ($ head_img, $ middle_img, $ footer_img, $ save_path) {2 $ source_w = 400; 3 $ source_h = 1142; 4 // Obtain the head image 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 ); // the start position of the header 9 // Obtain the size of the intermediate Image 10 $ midd_size = getimagesize ($ middle_img); 11 $ midd_height = $ midd_size ['1']; 12 $ midd_width = $ midd_size ['0']; 13 $ midd_start_y = $ head_height-15; // start Y coordinate in the middle, because there is a blank space at the bottom of the header image, therefore, subtract 1514 $ midd_start_x = floor ($ source_w-$ midd_width)/2); 15 16 // take the bottom image size 17 $ foot_size = getimagesize ($ footer_img ); 18 $ foot_height = $ foot_size [1]; 19 $ foot_width = $ foot_size [0]; 20 $ foot_start_x = floor ($ source_w-$ foot_width)/2 ); // The bottom image x coordinate 21 $ foot_start_y = $ source_h-$ foot_height; // The bottom image y coordinate 22 23 $ head = imagecreatefrompng ($ head_img ); 24 $ middle = upper ($ middle_img); 25 $ footer = imagecreatefrompng ($ footer_img); 26 27 $ bg_img = imageCreatetruecolor ($ source_w, $ source_h ); // Generate the background image 28 $ color = imagecolorallocate ($ bg_img, 255,255,255); // Set the white background 29 imagefill ($ bg_img, 0, 0, $ color ); // fill the background color with 30 imageColorTransparent ($ bg_img, $ color); // Transparent 31 imagecopyresampled ($ bg_img, $ head, $ head_start_x, 0, 0, 0, $ head_width, $ head_height, $ head_width, $ head_height); 32 bytes ($ bg_img, $ middle, $ midd_start_x, $ midd_start_y, 0, $ midd_width, $ midd_height, $ midd_width, $ midd_height ); 33 imagecopyresampled ($ bg_img, $ footer, $ foot_start_x, $ foot_start_y, 0, $ foot_width, $ foot_height, $ foot_width, $ foot_height); 34 35 imagepng ($ bg_img, $ save_path); 36} 37 $ head = dirname (_ FILE __). '/public/images/head.png'; 38 $ midd = dirname (_ FILE __). '/public/images/midd1.png'; 39 $ foot = dirname (_ FILE __). '/public/images/foot1.png'; 40 $ save_path = dirname (_ FILE __). "/public/images/testcomblie.png"; 41 combineImage ($ head, $ midd, $ foot, $ save_path );

Merge: you need to merge several images in the project. for example, you need to combine the images from the header, body, and legs. the code is as follows: 1 function combineImage ($ head_img...

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.