JustCarmen / webtrees-fancy-imagebar

Fancy Imagebar module for webtrees
http://justcarmen.nl
GNU General Public License v3.0
12 stars 6 forks source link

Fancy ImageBar 2.0.10: many duplicate thumbnails shown #62

Closed reteP-riS closed 3 years ago

reteP-riS commented 3 years ago

I am using a specific folder for portrait pictures. I currently have 36 .jpg files in that folder and opted out from the square thumbnails. My super wide screen can display 32 of them, each at a width of 60px. With webtrees 1.7.17 and Fancy ImageBar 1.7.11 all 32 pictures are different.

Now with webtrees 2.0.11 and Fancy ImageBar 2.0.10 - with the non working opt-out from square thumbnails, see the respective GitHub issue 61 - many duplicate thumbnails are being shown on every singe refresh. Sometimes the same picture is even shown consecutively 3 times.

reteP-riS commented 3 years ago

Above issue exists with both php 7.3.25 and php 7.4.13.

reteP-riS commented 3 years ago

It is the shuffle($resources) in FancyImagebarModule.php in case the canvas requires more pictures than are available in the selected folder and after repeating the existing pictures to fill the canvas, that creates the duplicate thumbnails so close to each other that the result is a bit ugly: https://github.com/JustCarmen/webtrees-fancy-imagebar/blob/master/FancyImagebarModule.php#L349-L355

        // Repeat items if neccessary to fill up the Fancy Imagebar
        if (count($resources) < $num_thumbs) {
            // see: https://stackoverflow.com/questions/2963777/how-to-repeat-an-array-in-php
            // works in php 5.6+
            $resources = array_merge(...array_fill(0, $num_thumbs - count($resources), $resources));
            shuffle($resources);
        }

May I suggest to simply remove line 354 https://github.com/JustCarmen/webtrees-fancy-imagebar/blob/master/FancyImagebarModule.php#L354 from the code.

            shuffle($resources); \\ remove this line

May I further suggest to change the canvas width from 2400 to 3840 px for 4K displays in line 312: https://github.com/JustCarmen/webtrees-fancy-imagebar/blob/master/FancyImagebarModule.php#L312

        $canvas_width  = 2400; \\ change to 3840