How can I render or change programmatically the responsive image style for an image field for a paragraph? I want to allow the editor user to be able to select different responsive image styles to render an image field from a paragraph field. So I have defined another field where the user can select the responsive style they want.

The problem is that I can't apply that responsive style on the fly on the twig template, so I tried to altered the field or create the picture element and assign it to a variable I can access from the template in the hook_preprocess_field, but I can't access the url of the image in the variables. So I don't know how to carry on.

Is there a way to achieve this?
You don't need to swap the image, only the information how to render the image. And you can't do this in a field template. This is only possible in the paragraph template, where both fields are available:

function mytheme_preprocess_paragraph(&amp;$variables) {
  if ($variables['paragraph']-&gt;hasField('field_image_style')) &amp;&amp; isset($variables['content']['field_image']['0']) {
    $image_style = $variables['paragraph']-&gt;field_image_style-&gt;value;
    $variables['content']['field_image']['0']['#responsive_image_style_id'] = $image_style;
  }
}