Passing string to a resize() in a snippet

I think it’s just my lack of php knowledge. :sweat_smile:
When I fill the $s1x with just a number, it works.
But if it’s astring it won’t. The Error message:

Argument #1 ($width) must be of type ?int, string given

I tried diffrent ways to «convert» the string into an integer but without success.

// template
<?php snippet("picture", [
  'image' => $image,
  's1x'   => $s1x = "null,100", 
  's2x'   => $s2x = "null,200",  
]) ?>
// snippet
<picture>
  <?php
      $i1x = $image->resize($s1x)->url(); 
      $i2x = $image->resize($s2x)->url(); 
  ?>            
  <source media="(max-width: 700px)" srcset="<?= $i1x ?> 1x, <?= $i1x ?> 2x">
  <source srcset="<?= $i1x ?> 1x, <?= $i2x ?> 2x">
  <img src="<?= $i1x ?>" alt="">
</picture>

Is this feasible?

I’d pass an array and then use the array values

's1x'   => [null, 100],

Then in snippet

 $i1xUrl = $image->resize($s1x[0], $s1x[1])->url(); 

Or using the splat operator:

 $i1xUrl = $image->resize(...$s1x)->url(); 

In any case, you cannot pass a string, because a list of arguments is not a string.

Wondering why you are not using the srcset() method?

Well, I did not use it, because I wasn’t aware of it. :person_facepalming: