• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

PHP Combining Multiple Images

Hi I have a problem with combining 36 small square images into one 6 by 6 mosaic image

What i ve done so far is coding to combine it in a single row with 6 squares. Now I ve trouble starting

 a new row as 2-1 when the first row has 6 squares [1-6]

[1-1 ][1-2 ][1-3 ][1-4 ][1-5 ][1-6 ]
[2-1 ][2-2 ][2-3 ] and so on.......
[3-1 ]
[4-1 ]
[5-1 ]
[6-1 ]

anyone can help me out ?
0
chockmilk
Asked:
chockmilk
  • 2
1 Solution
 
nizsmoDeveloperCommented:
What exactly is the trouble?

Lets say these are your pictures, what about putting a <br> at the end of [1-6]:

[1-1 ][1-2 ][1-3 ][1-4 ][1-5 ][1-6 ]<br>
[2-1 ][2-2 ][2-3 ] and so on.......
[3-1 ]
[4-1 ]
[5-1 ]
[6-1 ]

Let me know how you go.
0
 
chockmilkAuthor Commented:
thanks for the suggestion but what i want is combine them into one image and can be saved when user

right click and save as. This involve using PHP image function.
0
 
steelseth12Commented:
try this

header("Content-Type: image/jpeg");

      $images = array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image6.jpg","image7.jpg","image8.jpg","image9.jpg","image10.jpg","image11.jpg","image12.jpg");
      
      $columns = 6;
      
      $rows = ceil(count($images)/$columns);

      list($width, $height) = getimagesize($images[0]);
      
      $big_width = $width*$columns;
      
      $big_height = $height*$rows;
      
      $img = imagecreatetruecolor($big_width,$big_height);
      
      $y_cord = 0;
      
      $x_cord = 0;
      
      for($x=0; $x < count($images); $x++) {
      
            if(!($x%$columns) && $x !=0) {
            
                  $y_cord += $height;
                  
                  $x_cord = 0;
            }

                  
            $im1 = imagecreatefromjpeg($images[$x]);
            
            imagecopy($img,$im1,$x_cord,$y_cord,0,0,$width,$height);

            $x_cord += $width;


      }


      imagejpeg($img);
0
 
chockmilkAuthor Commented:
Hi Guru

This is what exactly i been looking for.

Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now