# How to use srcset() method?

**URL:** <https://forum.getkirby.com/t/how-to-use-srcset-method/21746>\
**Category:** Questions\
**Tags:** v3\
**Created:** [March 25, 2021, 9:39am UTC](https://forum.getkirby.com/t/how-to-use-srcset-method/21746 "2021-03-25T09:39:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrieng](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/adrieng/32/14454_2.png) [@Adrieng](https://forum.getkirby.com/u/Adrieng)\
**Post date:** [March 25, 2021, 9:39am UTC](https://forum.getkirby.com/t/how-to-use-srcset-method/21746/1 "2021-03-25T09:39:30Z")

</div>

Hello,

I don’t know how to use the srcset() method.

I tried with different samples that are written in [the doc](https://getkirby.com/docs/reference/objects/file/srcset) but it produces an empty srcset attribute each time.  
To be more precise, I tried :

- `$image->srcset([800, 1600])`
- `$image->srcset([800 => '1x', 1600 => '1.5x']); `

What should it produces precisely ? Two resized version of the given image and the associated srcset attribute ? That would be great ! But I can’t make it work. Did I miss something ?

Here is my full code :

```auto
<?php 
            $allBlocks = [];
            
            foreach($site->children()->listed() as $project) {

                if ($project->blocks()->isNotEmpty()) {
                    $pictures = $project->blocks()->toStructure();

                    foreach ($pictures as $picture) {
                        if ($picture->home() == "true") {
                            $block = [
                                "pic" => $picture->pic()->toFile()->resize(2000),
                                "projectTitle" => $project->title(),
                                "caption" => $picture->caption(),
                                "link" => $project->url(),
                                "ref" => $project->ref()
                            ];
                            
                            array_push($allBlocks, $block);
                        }
                    }
                }
            };

            if ($site->orderprojects() == 'false') shuffle($allBlocks);
            foreach($allBlocks as $block) {
                echo '<a class="toProject toProject--wait" data-title="' . $block["projectTitle"] . '" href="' . $block["link"] . '">';
                echo '<figure class="block hide">';
                echo "<img class=\"block__image\" src=\"" 
                    . $block["pic"]->url() 
                    . "\" srcset=\"" . $block["pic"]->srcset([
                        800 => '1x',
                        1600 => '1.5x'
                    ]) 
                    . "\" />";
                echo '<figcaption class="block __caption">' . '<span class="block__ ref">' . $block["ref"] . '</span> ' . $block["caption"] . '</figcation>';
                echo '</figure>';
                echo "</a>";
            }
        ?>

```

---

<div class="post-metadata">

**Author:** ![pixelijn](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@pixelijn](https://forum.getkirby.com/u/pixelijn)\
**Post date:** [March 25, 2021, 10:05am UTC](https://forum.getkirby.com/t/how-to-use-srcset-method/21746/2 "2021-03-25T10:05:24Z")

</div>

You are trying to call srcset on a thumb which is not possible. You have to call it on the original image.
