Double images on foreach loop

For some reason this snippet prints double images of every image coming from the media-page.
Not sure how this happend. Beside that I’m also spotting new duplicate files being created in the content folder. Does this has something to do with the crop I’m making?

for example:
thy3-1536x1536.jpeg —> original
thy3-1536x1536-min.jpeg —> duplicate (or is it a minified version?)

I hope you’ll spot the bug :slight_smile:

the snippet:

 <?php if ($site->page('media')->images()->isNotEmpty()): ?>
    <?php foreach ($site->page('media')->images() as $image): ?>
        <div class="swiper-slide">
        <a href="<?= $image->url() ?>" class="glightbox" data-gallery="gallery">
            <figure>
                <picture>
                    <source srcset="<?= $image->srcset([
                        '400w'  => ['width' => 400, 'height' => 400, 'crop' => 'center', 'format' => 'avif'],
                        '800w'  => ['width' => 800, 'height' => 800, 'crop' => 'center', 'format' => 'avif'],
                        '1200w' => ['width' => 1200, 'height' => 1200, 'crop' => 'center', 'format' => 'avif']
                        ]) ?>" type="image/avif">
                    <source srcset="<?= $image->srcset([
                        '400w'  => ['width' => 400, 'height' => 400, 'crop' => 'center', 'format' => 'webp'],
                        '800w'  => ['width' => 800, 'height' => 800, 'crop' => 'center', 'format' => 'webp'],
                        '1200w' => ['width' => 1200, 'height' => 1200, 'crop' => 'center', 'format' => 'webp']
                        ]) ?>" type="image/webp">
                    <img src="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%271200%27 height=%271800%27 style=%27background:%23a9bacf%27 /%3E" 
                        srcset="<?= $image->srcset([
                        '400w'  => ['width' => 400, 'height' => 400, 'crop' => 'center', 'format' => 'jpeg'],
                        '800w'  => ['width' => 800, 'height' => 800, 'crop' => 'center', 'format' => 'jpeg'],
                        '1200w' => ['width' => 1200, 'height' => 1200, 'crop' => 'center', 'format' => 'jpeg']
                        ]) ?>" alt="A highly optimized image">
                </picture>
                <figcaption><?= $image->caption() ?></figcaption>
            </figure>
        </a>
        </div>
    <?php endforeach ?>
    <?php endif ?>

If there are duplicate images with different file names in the source folder, it’s not really surprising that you also get duplicate output. So the question is, where do the duplicates in the content folder come from? Are you running a hook on file.create?

As I deleted the files and re-uploaded them again I saw that it only made the files with the ‘-min’ extension. So It seems to have resolved itself. No extra files being created as it seems.

Sorry, I should have tried that before coming here :sweat_smile: