Page MenuHomePhabricator

Different sizing of last image in <gallery mode="packed">
Open, Needs TriagePublic


In galleries with mode="packed" the last image in the gallery is unexpectedly downscaled under certain conditions.

Steps to reproduce:

  1. Go to
  2. Resize your browser window to a width of about 600px

Expected result: The three identical images should be sized equally
Actual result: The last image is smaller than the others

See also

Edit: It seems that not only the last image is effected, but the last row. I updated the test case, so that this effect is visible with two images in the last row (with window width of 1230px).

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

A similar example I assume:
Current view with JS enhancement:

obraz.png (541×914 px, 639 KB)


<gallery mode="packed" heights="150">
Plik:Timisoara Biserica Str. Bolyai (1).JPG|Fasada
Plik:Temesvár, Alexandriai Szent Katalin-templom belső tere 2022 01.jpg|Wnętrze
Plik:Temesvár, Alexandriai Szent Katalin-templom belső tere 2022 03.jpg|Ołtarz główny
Plik:Temesvár, Alexandriai Szent Katalin-templom belső tere 2022 07.jpg|Ołtarz [[Ukrzyżowanie Jezusa Chrystusa|Ukrzyżowania]]
Plik:Temesvár, Alexandriai Szent Katalin-templom belső tere 2022 08.jpg|Organy

So, as you can see from the code, the user's intention was to keep the same heights for all images, but after the changes made in JS, the height of the last image differs from the others.

A more modern approach. I think it would be a good idea to rewrite the support for these galleries as there are now better tools available that are built into browsers. The display flex is very stable and has extensive support.

I've made a proof of concept which would obviously require more extensive testing, but I think there's a chance it will just work.

Step. 1. Remove static width (or just don't add them in the 1st place):

document.querySelectorAll(' [style]').forEach(a=>'')

Step. 2. Disable current JS that changes widths on resize.

Step. 3. CSS. {
	display: flex;
	flex-wrap: wrap;
	gap: 1em;
	align-items: baseline;
	justify-content: center;
} li {
/* 	flex: 1; */
} div.thumb img {
	width: auto;
	height: 200px;	/* should be set by users */

This is a working version. The gallery after these changes looks like this:

obraz.png (505×919 px, 630 KB)

Much better for my taste 🙂...

Configuration for users The only thing left now is the problem of user height control. I think the easiest way to do this is through CSS variables.

So <gallery mode="packed" heights="200"> could render as:

<ul class="gallery mw-gallery-packed" style="--gallery-height: 200px;">

And the CSS would be: div.thumb img {
	width: auto;
	height: var(--gallery-height);

That just works 🙂.

Only problem is with current JS that is re-setting widths. So at the moment after each resize you will need to run this again:

document.querySelectorAll(' [style]').forEach(a=>'')