All Projects → mendrik → diorama

mendrik / diorama

Licence: Apache-2.0 License
An image layout algorithm

Programming Languages

typescript
32286 projects
CSS
56736 projects
javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to diorama

Perfect Layout
Image layout generator based on linear partitioning
Stars: ✭ 312 (+1735.29%)
Mutual labels:  gallery, layout, images
React Grid Gallery
Justified image gallery component for React
Stars: ✭ 571 (+3258.82%)
Mutual labels:  gallery, images
Nanogallery2
a modern photo / video gallery and lightbox [JS library]
Stars: ✭ 488 (+2770.59%)
Mutual labels:  gallery, images
Photo view
📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.
Stars: ✭ 1,280 (+7429.41%)
Mutual labels:  gallery, images
grid-layout
grid-layout is a layout engine which implements grid, can use in canvas/node-canvas
Stars: ✭ 43 (+152.94%)
Mutual labels:  layout, grid-layout
V Img
Stars: ✭ 400 (+2252.94%)
Mutual labels:  gallery, images
Collectionviewpaginglayout
a simple but highly customizable paging layout for UICollectionView.
Stars: ✭ 947 (+5470.59%)
Mutual labels:  gallery, layout
Magic Grid
A simple, lightweight Javascript library for dynamic grid layouts.
Stars: ✭ 2,827 (+16529.41%)
Mutual labels:  layout, grid-layout
React Slideshow
A react component for slideshow supporting slide, fade and zoom
Stars: ✭ 201 (+1082.35%)
Mutual labels:  gallery, images
MediaSliderView
Pure java based, highly customizable media slider gallery supporting both images and videos for android.
Stars: ✭ 85 (+400%)
Mutual labels:  gallery, images
react-simple-image-viewer
Simple image viewer component for React
Stars: ✭ 44 (+158.82%)
Mutual labels:  gallery, images
Floral
Minimal design gallery app for Android.
Stars: ✭ 23 (+35.29%)
Mutual labels:  gallery, images
Simple React Lightbox
A simple but functional light-box for React.
Stars: ✭ 265 (+1458.82%)
Mutual labels:  gallery, images
Vue Gallery
📷 Responsive and customizable image and video gallery, carousel and lightbox, optimized for both mobile and desktop web browsers.
Stars: ✭ 405 (+2282.35%)
Mutual labels:  gallery, images
React Css Grid
React layout component based on CSS Grid Layout and built with styled-components
Stars: ✭ 239 (+1305.88%)
Mutual labels:  layout, grid-layout
React Native Image Gallery
Pure JavaScript image gallery component for iOS and Android with high-performance and native feeling in mind
Stars: ✭ 601 (+3435.29%)
Mutual labels:  gallery, images
Popo
PoPo is the grid layout tool, the best choice for runtime layout.
Stars: ✭ 130 (+664.71%)
Mutual labels:  layout, grid-layout
Bedrock
Foundational Layout Primitives for your React App
Stars: ✭ 173 (+917.65%)
Mutual labels:  layout, grid-layout
Silentbox
A lightbox inspired Vue.js component.
Stars: ✭ 196 (+1052.94%)
Mutual labels:  gallery, images
django-content-gallery
A Django application allows to attach a collection of images to objects of any model in any app
Stars: ✭ 18 (+5.88%)
Mutual labels:  gallery, images

Demo

Resize your browser window or rotate your mobile device to see full layout effect

Diorama

An image layout algorithm that distributes a set of images into a fixed sized rectangle. Please note that the algorithm is heuristic and works best, when there is a sufficient amount of images to find a good solution, usually 5 or more images.

Usage

npm install diorama

import  { searchSolution }  from 'diorama'

// aspectRatios are the w/h value array of your image set
const nodes: Node[] = searchSolution(800, 600, aspectRatios, 500)
// each node has x,y,width,height based on the first 2 arguments 

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Background

A few years ago I was tasked to write an image layout algorithm that would create a gallery from a set of images in a fixed sized rectangle. I have initially looked into this problem by checking out existing solutions, the most satisfying ones were based on partitioning a single row of images and adjusting the heights to meet the aspect ratios. However none of them seemed to deal with a fixed height as well. Other solutions like stacking boxes on a grid left unfilled gaps or had to crop the images too much to look nice.

So after a lot of thinking I finally had an idea which I will elaborate a bit. At the core we can always combine two images to a new rectangle. Given the aspect ratios of two images a1 and a2, we can combine them either horizontally or vertically and the new aspect ratios can be easily calculated with a1 + a2 or (a1 * a2) / (a1 + a2) respectively.

Now we can create a full binary and balanced tree for a set of images (the lowest leaves), however since the image count needs to be a power of two I need to fill up the set with dummies to meet the right amount of leaves. The dummies behave like single lines and are not visible in the final rendering. Once this is done I go ahead and shuffle the leaves and then climb the tree upwards with each node also randomly choosing which aspect ratio formula to pick (vertical vs horizontal combination). When we reach the root node its aspect ratio can be compared to the aspect ratio of the target canvas. The closer the match, the less cropping of images is required.

Another problem was that some solutions would scale up single images too much and leave the rest too small to look nice. So evaluating the solutions includes also calculating the real sizes and making sure we discard solutions with too much variations in image sizes, even if it means the cropping might increase.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].