Search code examples
phpimageimagemagickgd

Virtual gridding/resizing of image collage in PHP


I'm looking for a finshed solution or possibly some math/algorithms for creating a big image collage out of smaller product pictures? I know how to do it in a square fashion, from same sized pictures with gd/imagemagick but I'd like to have some variation built in.

For example, some of the pictures might be slightly taller, and if all are the same size and square - i might want 1 of them take up more space, just to mix up the design. keeping it interesting.

the more i think about this the harder it seems to do with a formula. having predefined "templates" for all the possible scenarios isn't going to work since the amount of pictures could vary from just 1 (no work needed) to 10+.

i'm not looking for any rotation or special effects, just the images in a grid with maybe some spacing inbetween and no overlapping.

any ideas how to accomplish this, and is there really nothing ready to go out there?


Solution

  • I suggest you to create a grid and weight approach.

    This answer is divided in 3 parts :

    1. Working with a virtual grid
    2. Randomly dispose image into that grid
    3. Implement transparency