from Hacker News

JQuery plugin to arrange images using knapsack algorithm

by sushi on 4/24/12, 7:53 AM with 29 comments

  • by vog on 4/24/12, 8:19 AM

    Great idea! However, the term "knapsack algorithm" is quite misleading.

    There is the "knapsack problem", but there are various different algorithms to solve it. Which of those has been used? Why this and not another algorithm? All those questions are concealed behind the squishy term "knapsack algoritm".

  • by omgmog on 4/24/12, 8:22 AM

    Whipped up a quick example, it seems to re-order the images in a way to fit the most it can on each row given the width constraints and the width of each image - http://jsfiddle.net/vXbCY/
  • by zsherman on 4/24/12, 8:14 AM

    I wish there was a quick link to an example.
  • by riffraff on 4/24/12, 8:17 AM

    what is the "knapsack algorithm" ?

    I understand how arranging images may be a "knapsack problem" but I can't pinpoint what the algorithm is supposed to be.

  • by jmathai on 4/24/12, 8:21 AM

    I believe this is similar to the layout used for G+ photos and Flickr's new justified view. Am I right?

    We adapted the script below for http://current.openphoto.me/photo/list --- curious to check this out as well.

    http://www.techbits.de/2011/10/25/building-a-google-plus-ins...

  • by moe on 4/24/12, 12:25 PM

    Aren't most (all?) knapsack solvers greedy?

    That doesn't seem like a good idea just to arrange some images (battery killer?).

  • by gauravsc on 4/24/12, 8:30 AM

    Plugin co-author here: One more possible extension of this algo would be to use value of each image equal to the weight of each image. This would ensure best fit and would be one more way to make things look beautiful and arranged.
  • by dangoldin on 4/24/12, 2:03 PM

    Pretty interesting stuff. Have you heard of the Isotope jQuery library? It does something similar.

    How is the performance on this one?