JustifiedGallery
JustifiedGallery is the algorithm part needed to compute a grid of images a la flickr explore page.
Demo
You can check a plain vanilla javascript demo here
Instalation
In your project
npm install justifiedgallery --save
Since it's an npm module, use it with webpack or browserify
Usage
import PhotoGrid from 'justifiedgallery';
let images = [imgMeta1, imgMeta2];
let grid = new PhotoGrid({
minHeight: 150,
maxHeight: 350,
borderWidth: 2,
getImageMeta: (image) => {
image.width = image.originalDimensions.width;
image.height = image.originalDimensions.height;
return image;
},
filesGetter: (image) => {
let resizedImages = image.resizedImages;
return resizedImages;
}
}, images);
let containerWidth = document.getElementById("myGridContainer").clientHeight;
let rows = grid.getRows(containerWidth);
let row0 = rows[0];
let imagesToShowOnFirstRow = row0.getItems();
So the component should be used with any view framework -> e.g. jQuery, jsx, vanilla js and so on.