PHP Combining Multiple Images

Posted on 2007-10-15
Last Modified: 2013-12-13
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 ?
Question by:chockmilk
    LVL 21

    Expert Comment

    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.

    Author Comment

    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.
    LVL 20

    Accepted Solution

    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]);

                $x_cord += $width;



    Author Comment

    Hi Guru

    This is what exactly i been looking for.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now