
I always didn’t like the way the images on my sites are displayed. I wanted some sort of ordering, dependency. Therefore, I found it useful to search for scripts and solutions in Google. After unsuccessful searches, it was decided to do something myself.
But what? I began to look, as the conclusion of pictures at popular sites is made. I didn't like everything until I thought of seeing the output in google images and google +. It struck me that
I never noticed that the pictures are aligned in width and height without clipping. This principle I wanted to implement. It turns out the mosaic. And everything seems to be in its place.
Without hesitation, I sat down to write code that can display pictures in the same way.
I decided to make it very simple: to make each line of a certain height and width. The main thing is that the height should not be greater than that which we set in the conditions.
Formulas
Armed with a marker and a fridge (yes, I don’t have a marker board), I made up a few simple equations and found a dependency.
h
1 * X
1 = h
2 * X
2 = ... = h
n X
n = height (height);
w
1 * X
1 + w
2 * X
2 + ... + w
n * X
n = width (width);
Where
h
1 -n - heights of images
w
1-n - the width of the image.
X
1-n - variable scaling (if you multiply the height and width by it, the picture will change proportionally).
')
It turns out that height = width * h
1 / (w
1 + w
2 * h
1 / h
2 + w
3 * h
1 / h
3 + ... + w
n * h
1 / h
n ).
Code
$widthdef=800;
If there are not enough pictures to output across the entire width, output them with the maximum height specified.
From the author
The code is not perfect, so comments are taken into account.
You can see the demo
here . There you can play around with the parameters. When loading the image is resized to the lowest possible resolution. Hosting is weak, I apologize in advance for lags.
Download
here .
I also want to hear other ideas and improvements.
PS: The code is not provided for small images (I personally do not need it). If you load large and small, the latter can stretch. If anyone comes up with an elegant solution, share.
UPD: Thanks for the comments, very helpful. I will be improved. Error corrected. As already said, all the pictures are still
here (removed by the crown after 3 hours).