Answers.Body: <p><code>landscapeMd</code> and <code>portraitMd</code> are <em>variables</em>... they would need to be <strong>strings</strong> (or array keys) for this to work.</p>
  
  <p>Try something like this:</p>
  
  <pre><code>{# medium 16:9 #}
  {% set landscapeMd = {
    width: 439,
    height: 247,
    quality: 80,
  } %}
  
  {# medium 9:16 #}
  {% set portraitMd = {
    width: 278,
    height: 494,
    quality: 80,
  } %}
  
  {% set transforms = {
    'landscapeMd': landscapeMd,
    'portraitMd': portraitMd
  } %}
  
  {% for block in entry.productCollage %}
    {% switch block.type %}
      {% case "digitalProduct" %}
        // selected via dropdown field
        {% set transformType = transforms[block.imageAspectRatio.value] %}
  
        &lt;figure&gt;
          {% for image in block.image %}
            &lt;a href=""&gt;&lt;img src="{{ image.url(transformType) }}" alt=""&gt;&lt;/a&gt;
          {% endfor %}
        &lt;/figure&gt;
    {% endswitch %}
  {% endfor %}
  </code></pre>
  
  <p>This maps the transforms with the <code>transforms</code> object, then references the key in <code>transforms[block.imageAspectRatio.value]</code>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-16T20:38:26.177Z
Answers.LastActivityDate: 2017-06-16T20:38:26.177Z
Answers.UserDisplayName: Lindsey D
Body: <p>I've set up four custom image transforms on the page and would like the content editor to be able to select which size they want the image to be from a drodown field preconfigured with the transformation names. This is all within a Matrix field, btw. <a href="https://craftcms.stackexchange.com/questions/14679/using-image-transform-as-another-custom-field/14682">This answer was close</a>, and helped me put <code>.value</code> on the end of my dropdown field variable, but it must only work with pre configured image transforms in Craft's settings.</p>
  
  <p>Here is the code (simplified):</p>
  
  <pre><code>{# medium 16:9 #}
  {% set landscapeMd = {
    width: 439,
    height: 247,
    quality: 80,
  } %}
  
  {# medium 9:16 #}
  {% set portraitMd = {
    width: 278,
    height: 494,
    quality: 80,
  } %}
  
  {% for block in entry.productCollage %}
    {% switch block.type %}
      {% case "digitalProduct" %}
        // selected via dropdown field
        {% set transformType = block.imageAspectRatio.value %}
  
        &lt;figure&gt;
          {% for image in block.image %}
            &lt;a href=""&gt;&lt;img src="{{ image.url(transformType) }}" alt=""&gt;&lt;/a&gt;
          {% endfor %}
        &lt;/figure&gt;
    {% endswitch %}
  {% endfor %}
  </code></pre>
  
  <p>What I get with this code is an error that says the selected image transform is not available. However, if I type in that image transform verbatim, it works fine.</p>
  
Tags: <image-transforms>
Title: User-selected Image Transform
ThreadText: # User-selected Image Transform
  
  (Asked by: username_0 on 2017-06-16)
  
  I've set up four custom image transforms on the page and would like the content editor to be able to select which size they want the image to be from a drodown field preconfigured with the transformation names. This is all within a Matrix field, btw. [This answer was close](https://craftcms.stackexchange.com/questions/14679/using-image-transform-as-another-custom-field/14682), and helped me put `.value` on the end of my dropdown field variable, but it must only work with pre configured image transforms in Craft's settings.
  
  Here is the code (simplified):
  
  ```
  {# medium 16:9 #}
  {% set landscapeMd = {
    width: 439,
    height: 247,
    quality: 80,
  } %}
  
  {# medium 9:16 #}
  {% set portraitMd = {
    width: 278,
    height: 494,
    quality: 80,
  } %}
  
  {% for block in entry.productCollage %}
    {% switch block.type %}
      {% case "digitalProduct" %}
        // selected via dropdown field
        {% set transformType = block.imageAspectRatio.value %}
  
        <figure>
          {% for image in block.image %}
            <a href=""><img src="{{ image.url(transformType) }}" alt=""></a>
          {% endfor %}
        </figure>
    {% endswitch %}
  {% endfor %}
  
  ```
  
  What I get with this code is an error that says the selected image transform is not available. However, if I type in that image transform verbatim, it works fine.
  
  **Tags:** image-transforms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-06-16. Score: 1
  
  `landscapeMd` and `portraitMd` are *variables*... they would need to be **strings** (or array keys) for this to work.
  
  Try something like this:
  
  ```
  {# medium 16:9 #}
  {% set landscapeMd = {
    width: 439,
    height: 247,
    quality: 80,
  } %}
  
  {# medium 9:16 #}
  {% set portraitMd = {
    width: 278,
    height: 494,
    quality: 80,
  } %}
  
  {% set transforms = {
    'landscapeMd': landscapeMd,
    'portraitMd': portraitMd
  } %}
  
  {% for block in entry.productCollage %}
    {% switch block.type %}
      {% case "digitalProduct" %}
        // selected via dropdown field
        {% set transformType = transforms[block.imageAspectRatio.value] %}
  
        <figure>
          {% for image in block.image %}
            <a href=""><img src="{{ image.url(transformType) }}" alt=""></a>
          {% endfor %}
        </figure>
    {% endswitch %}
  {% endfor %}
  
  ```
  
  This maps the transforms with the `transforms` object, then references the key in `transforms[block.imageAspectRatio.value]`.
  
  
  ---
  
  