TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

JQuery plugin to arrange images using knapsack algorithm

46 pointsby sushiabout 13 years ago

8 comments

vogabout 13 years ago
Great idea! However, the term "knapsack algorithm" is quite misleading.<p>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".
评论 #3882999 未加载
omgmogabout 13 years ago
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 - <a href="http://jsfiddle.net/vXbCY/" rel="nofollow">http://jsfiddle.net/vXbCY/</a>
评论 #3882997 未加载
zshermanabout 13 years ago
I wish there was a quick link to an example.
评论 #3882979 未加载
riffraffabout 13 years ago
what is the "knapsack algorithm" ?<p>I understand how arranging images may be a "knapsack problem" but I can't pinpoint what <i>the algorithm</i> is supposed to be.
评论 #3883033 未加载
jmathaiabout 13 years ago
I believe this is similar to the layout used for G+ photos and Flickr's new justified view. Am I right?<p>We adapted the script below for <a href="http://current.openphoto.me/photo/list" rel="nofollow">http://current.openphoto.me/photo/list</a> --- curious to check this out as well.<p><a href="http://www.techbits.de/2011/10/25/building-a-google-plus-inspired-image-gallery/" rel="nofollow">http://www.techbits.de/2011/10/25/building-a-google-plus-ins...</a>
评论 #3883466 未加载
moeabout 13 years ago
Aren't most (all?) knapsack solvers greedy?<p>That doesn't seem like a good idea just to arrange some images (battery killer?).
gauravscabout 13 years ago
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.
dangoldinabout 13 years ago
Pretty interesting stuff. Have you heard of the Isotope jQuery library? It does something similar.<p>How is the performance on this one?
评论 #3884133 未加载