8

Is there any algorithm for arranging a lot of small images with different dimensions and group them into a larger one? Anyone have any idea from where should i start investigating?


EDIT: Basically i want to make something like this http://www.google.ro/images/srpr/nav_logo27.png in PHP. I'm not really expecting such complexity. I'm gonna use the image as a CSS sprite, if it makes any difference.

Quamis
  • 10,924
  • 12
  • 50
  • 66
  • Do you want to use the resulting image as a css sprite? – c0rnh0li0 Nov 23 '10 at 18:17
  • If it is one time only, you don't need algorithm. There are plenty of CSS sprite programs. – Ross Nov 25 '10 at 16:43
  • 1
    Even if you use quite an inefficient approach (so that it creates an image with larger dimensions) it shouldn't really matter much; most of the wasted space will be the same colour and will compress well, so your overall image size won't be all that much bigger. Use client side caching and they'll only download the image once... so don't waste too much time on this problem. – El Yobo Nov 28 '10 at 05:10

3 Answers3

6

Generally it is hard computational problem, but approximate solutions exist.

Edit: Related question Packing rectangular image data into a square texture

Community
  • 1
  • 1
Ross
  • 2,079
  • 2
  • 22
  • 26
1

Using an optimization algorithm could be an overkill for your problem. Coding an optimization algorithm will require a lot of pre-study. Even implementing a ready library could be a big problem to tackle.

You can devise a heuristic, by yourself:
Use the large image's width and height as your input.
Think of it as if you fill up each row and continue to the next row once the row is filled up. And start inserting images one by one.

If you use an algorithm the final image will be more optimized. Smaller in size. But the difference would not be much different if your images do not vary a lot in dimensions.

If your image dimensions do vary a little, order them according to their most varying dimension (either width or height). Then start inserting the images in that order.

Haluk
  • 2,091
  • 2
  • 27
  • 35
0

I think this is called mosaic, so you can start by looking this up

davka
  • 13,974
  • 11
  • 61
  • 86