Defining var with condition in value

I’m trying to do that in a shortcode:

{% set style1 = "style=\"display: inline-block; {% if w1 %}width: {{w1}}px;{% endif %}{% if h1 %}height: {{h1}}px;{% endif %} margin-right: 2.5em;\""%}
<div style="text-align: center;">
{% if c1 %}<p {{style1}}>{% endif %}
{% if l1 %}<a href="{{l1}}">{% endif %}
<img src="{{s1}}" {% if not c1 %}{{style1}}{% endif %}/>
{% if l1 %}</a>{% endif %}
{% if c1 %}<em>{{c1}}</em></p>{% endif %}
</div>

but it fails when parsing the `set` instruction:

Error: Reason:

  • Failed to parse “//?/L:\Dev\blog\templates\shortcodes\dimg.html”
    → 1:26
    |
    1 | {% set style1 = “style="display: inline-block; {% if w1 %}width: {{w1}}px;{% endif %}{% if h1 %}height: {{h1}}px;{% endif %} margin-right: 2.5em;"”%}
    | ^—
    |
    = expected or, and, not, <=, >=, <, >, ==, !=, a filter, or %} or -%}

What am I missing? Or is it even possible?