PHP image Synthesis (multiple images to compose a picture)

Source: Internet
Author: User

1. Multiple pictures to synthesize a picture such as:

Picture compositing, can be displayed in the browser and save to the folder below

<?PHP/** * Image Merge **/        $pic _list=Array(          ' Img2.png ', ' img2.png ', ' logo.png ', ' logo.png ', ' logo.png ', ' img2.png ', ' Img2.png ', ' img2.png ', ' img2.png '      ); $pic _list=Array_slice($pic _list, 0, 9);//only first 9 pictures      $BG _w= 150;//Background Image width    $BG _h= 150;//Background Image Height      $background= Imagecreatetruecolor ($BG _w,$BG _h);//Background Image    $color= Imagecolorallocate ($background, 202, 201, 201);//Create a white background for the true color canvas and set it to transparentImagefill ($background, 0, 0,$color); Imagecolortransparent ($background,$color); $pic _count=Count($pic _list); $LINEARR=Array();//where line breaks are needed    $space _x= 3; $space _y= 3; $line _x= 0; Switch($pic _count) {       Case1://right in the middle        $start _x=intval($BG _w/4);//Start position x        $start _y=intval($BG _h/4);//Start position y        $pic _w=intval($BG _w/2);//width        $pic _h=intval($BG _h/2);//Height         Break;  Case2://Middle Position side -by        $start _x= 2; $start _y=intval($BG _h/4) + 3; $pic _w=intval($BG _w/2)-5; $pic _h=intval($BG _h/2)-5; $space _x= 5;  Break;  Case3:$start _x= 40;//Start position x        $start _y= 5;//Start position y        $pic _w=intval($BG _w/2)-5;//width        $pic _h=intval($BG _h/2)-5;//Height        $LINEARR=Array(2); $line _x= 4;  Break;  Case4:$start _x= 4;//Start position x        $start _y= 5;//Start position y        $pic _w=intval($BG _w/2)-5;//width        $pic _h=intval($BG _h/2)-5;//Height        $LINEARR=Array(3); $line _x= 4;  Break;  Case5:$start _x= 30;//Start position x        $start _y= 30;//Start position y        $pic _w=intval($BG _w/3)-5;//width        $pic _h=intval($BG _h/3)-5;//Height        $LINEARR=Array(3); $line _x= 5;  Break;  Case6:$start _x= 5;//Start position x        $start _y= 30;//Start position y        $pic _w=intval($BG _w/3)-5;//width        $pic _h=intval($BG _h/3)-5;//Height        $LINEARR=Array(4); $line _x= 5;  Break;  Case7:$start _x= 53;//Start position x        $start _y= 5;//Start position y        $pic _w=intval($BG _w/3)-5;//width        $pic _h=intval($BG _h/3)-5;//Height        $LINEARR=Array(2,5); $line _x= 5;  Break;  Case8:$start _x= 30;//Start position x        $start _y= 5;//Start position y        $pic _w=intval($BG _w/3)-5;//width        $pic _h=intval($BG _h/3)-5;//Height        $LINEARR=Array(3,6); $line _x= 5;  Break;  Case9:$start _x= 5;//Start position x        $start _y= 5;//Start position y        $pic _w=intval($BG _w/3)-5;//width        $pic _h=intval($BG _h/3)-5;//Height        $LINEARR=Array(4,7); $line _x= 5;  Break; }      foreach($pic _list  as $k=$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 the position of the _y copy picture in the background//0,0 the position of the Copy picture//$pic _w, $pic _h the height and width of the copyImagecopyresized ($background,$resource,$start _x,$start _y, 0, 0,$pic _w,$pic _h, Imagesx ($resource), Imagesy ($resource));//The last two parameters are the original width and height of the image, the width and height of the picture when the reciprocal two parameters are copy        $start _x=$start _x+$pic _w+$space _x; }        Header("Content-type:image/jpg"); Imagejpeg ($background); Imagegif ($background, "./hero_gam.png"); ?>
Image Synthesis

2. Get the height and width of the source picture

List ($width, $height) = getimagesize ($file);

PHP image Synthesis (multiple images to compose a picture)

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.