# Image selection in loop

**URL:** <https://forum.getkirby.com/t/image-selection-in-loop/24173>\
**Category:** Questions\
**Tags:** v3\
**Created:** [December 6, 2021, 10:45pm UTC](https://forum.getkirby.com/t/image-selection-in-loop/24173 "2021-12-06T22:45:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![marc22761](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@marc22761](https://forum.getkirby.com/u/marc22761)\
**Post date:** [December 6, 2021, 10:45pm UTC](https://forum.getkirby.com/t/image-selection-in-loop/24173/1 "2021-12-06T22:45:20Z")

</div>

I’m using a loop to load images into an article.

```auto
<?php if ($image = $article->picture()->toFile() ) : ?>
       <img src="<?= $image->url() ?>" class="img-fluid">
<?php endif; ?>

```

First issue, since using the webp plugin its always loading both the jpg and the webp image, therefore every image is showing twice.

Second issue, when somebody is changing a picture in the panel, the old picture is still showing since it is not being removed from the folder.

The reason of using a loop instead of named fields is, I don’t want to limit the number of pictures for the editor.

---

<div class="post-metadata">

**Author:** ![jimbobrjames](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jimbobrjames/32/5802_2.png) [@jimbobrjames](https://forum.getkirby.com/u/jimbobrjames)\
**Post date:** [December 6, 2021, 11:35pm UTC](https://forum.getkirby.com/t/image-selection-in-loop/24173/2 "2021-12-06T23:35:48Z")

</div>

Would this be my webp plugin? You can use the snippets for this, explained in the readme which can be used in a loop.

```auto
snippet('webp', ['sizes' => [1920, 1140, 640, 320], 'src' => 'yourimage.jpg', 'type' => 'png', 'class' => 'picturetagclass', 'width' => 800, 'height' => 600])

```

The source can be an image object, so something like this will work

```auto
  <?php foreach($page->images() as $image): ?>
   <?= snippet('webp', ['sizes' => [1920, 1140, 640, 320], 'src' => $image 'type' => 'jpg', 'class' => 'picturetagclass', 'width' => 800, 'height' => 600]) ?>
  <?php endforeach ?>

```

Personally i filter out the webp images from being displayed in the panel so as not to clutter it up. The snippet takes care of loading both formats.

However, i would strongly recommend removing the plugin and upgrading to the recently released Kirby 3.6 which has native webp and avif support.

---

<div class="post-metadata">

**Author:** ![marc22761](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@marc22761](https://forum.getkirby.com/u/marc22761)\
**Post date:** [December 7, 2021, 8:58am UTC](https://forum.getkirby.com/t/image-selection-in-loop/24173/3 "2021-12-07T08:58:30Z")

</div>

Thank you for your answer @jimbobrjames !

It’s the felixhaeberle/kirby3-webp plugin. I’m running 3.6.0 but used the plugin already before. Its a good idea to switch from the plugin to the native webp support.

> Personally i filter out the webp images from being displayed

How are you doing this?
