<p>Craft's built-in transform functionality doesn't support transforming external URLs. You could use my <a href="https://github.com/aelvan/Imager-Craft" rel="nofollow noreferrer">Imager plugin</a> to do this instead.</p>

<p>EDIT:</p>

<p>Based on your example, you'd use Imager something like this:</p>

<pre><code>{% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
{% if response.success %}
    {% for tweet in response.data %}
        {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}
                {% set transformedImage = craft.imager.transformImage(item.media_url, { width: 200, height: 200 }) %}
                &lt;div&gt;&lt;img src="{{ transformedImage.url }}" alt=""/&gt;&lt;/div&gt;
            {% endfor %}
        {% endif %}
    {% endfor %}
{% endif %}
</code></pre>

<p>So, the essential part is that you need to pick up the url to each item in the loop (<code>item.media_url</code>, if that's what the twitter plugin returns), and do the transform inside the for loop.</p>

CC BY-SA 4.0
2018-08-20T10:19:25.117Z
I knew there was a way of achieving this. I've even used this before, but couldn't think of what it was called. Gonna add this to my list of regular use plugins.
Jay
CC BY-SA 4.0
2018-08-20T20:41:14.983Z
@André, I did try implementing your plugin Imager, which works great for a single image (knowing the absolute path) but how do you find the path for multiple tweet (image) entries? See added code in the original question.
Nutmeg
CC BY-SA 4.0
2018-08-22T11:30:43.600Z
@Nutmeg I've updated my reply.
André Elvan
CC BY-SA 4.0
2018-08-20T10:15:36.047Z
2018-08-22T11:30:22.553Z
2018-08-22T11:30:22.553Z
André Elvan
<p>As far as I'm aware it's not possible, because the Twitter feed APIs are fed a URL path to the asset on Twitter's server. So Craft never handles the actual asset to be able to crop it.</p>

<p>I'm sure the P&amp;T guys or Andrew that usually respond to questions will have a suggestion, but I don't think it's really possible.</p>

<p>Best you can do it crop images in CSS using <code>object-fit: cover</code> in a div the size you want the image to be.</p>

<p>EDIT:</p>

<p>But the actual error you're getting is because <code>item.media_url</code>is a string for '<a href="http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg" rel="nofollow noreferrer">http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg</a>', so it doesn't have a url to access with <code>.getUrl</code>.</p>

<p>I'm unsure if it'll work, but you could try <code>item.media_url('footerThumbs')</code></p>

<p>Cheers</p>

CC BY-SA 4.0
2018-08-20T21:15:05.890Z
thank you, but I did try that. The solution will be in the Imager plugin, but the question is how....
Nutmeg
CC BY-SA 4.0
2018-08-20T21:28:56.547Z
I haven't used it for a long time unfortunately. Looks like Andre above is helping you. Good luck!
Jay
CC BY-SA 4.0
2018-08-20T09:21:48.393Z
2018-08-20T13:04:19.387Z
2018-08-20T13:04:19.387Z
Jay
<pre><code>  {% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
            {% if response.success %}
            {% for tweet in response.data %}
            {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}

            &lt;div&gt;&lt;img src="{{ item.media_url.getUrl('footerThumbs') }}" alt=""/&gt;&lt;/div&gt;
            {% endfor %}
            {% endif %}
            {% endfor %}
            {% endif %}
</code></pre>

<p>This throws a Runtime error: Impossible to invoke a method ("getUrl") on a string variable ("<a href="http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg" rel="nofollow noreferrer">http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg</a>").</p>

<p>What other method is possible?</p>

<p>Using the Imager plugin:
{% set externalImage = '<a href="http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg" rel="nofollow noreferrer">http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg</a>' %}</p>

<pre><code>{% set transformedImages = craft.imager.transformImage(externalImage, [
                { width: 200, height: 200 }])
              %}
         {% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
            {% if response.success %}
            {% for tweet in response.data %}
            {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}

            &lt;div&gt;&lt;img src="{{ externalImage }}" alt=""/&gt;&lt;/div&gt;
            {% endfor %}
            {% endif %}
            {% endfor %}
            {% endif %}}
</code></pre>

<image-transforms><plugin-imager><plugin-dukttwitter>
Apply imageTransform on twitter media feed
# Apply imageTransform on twitter media feed

(Asked by: username_0 on 2018-08-20)

{% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
            {% if response.success %}
            {% for tweet in response.data %}
            {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}

            
            {% endfor %}
            {% endif %}
            {% endfor %}
            {% endif %}

This throws a Runtime error: Impossible to invoke a method ("getUrl") on a string variable ("http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg").
What other method is possible?
Using the Imager plugin:
{% set externalImage = 'http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg' %}
{% set transformedImages = craft.imager.transformImage(externalImage, [
                { width: 200, height: 200 }])
              %}
         {% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
            {% if response.success %}
            {% for tweet in response.data %}
            {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}

            
            {% endfor %}
            {% endif %}
            {% endfor %}
            {% endif %}}

**Tags:** image-transforms, plugin-imager, plugin-dukttwitter

---

## 2 answers

### Answer by username_1 on 2018-08-20. Score: 3 | Accepted answer

Craft's built-in transform functionality doesn't support transforming external URLs. You could use my Imager plugin to do this instead.
EDIT:
Based on your example, you'd use Imager something like this:
{% set response = craft.twitter.get('statuses/user_timeline', { tweet_mode:'extended', count: 20 }) %}
{% if response.success %}
    {% for tweet in response.data %}
        {% if tweet.extended_entities.media is defined %}
            {% for item in tweet.extended_entities.media if item.type == 'photo' %}
                {% set transformedImage = craft.imager.transformImage(item.media_url, { width: 200, height: 200 }) %}
                
            {% endfor %}
        {% endif %}
    {% endfor %}
{% endif %}

So, the essential part is that you need to pick up the url to each item in the loop (item.media_url, if that's what the twitter plugin returns), and do the transform inside the for loop.

> **Comments:**
> **username_2**: I knew there was a way of achieving this. I've even used this before, but couldn't think of what it was called. Gonna add this to my list of regular use plugins.  
> **username_0**: @André, I did try implementing your plugin Imager, which works great for a single image (knowing the absolute path) but how do you find the path for multiple tweet (image) entries? See added code in the original question.  
> **username_1**: @Nutmeg I've updated my reply.  

---

### Answer by username_2 on 2018-08-20. Score: 0

As far as I'm aware it's not possible, because the Twitter feed APIs are fed a URL path to the asset on Twitter's server. So Craft never handles the actual asset to be able to crop it.

I'm sure the P&T guys or Andrew that usually respond to questions will have a suggestion, but I don't think it's really possible.

Best you can do it crop images in CSS using `object-fit: cover` in a div the size you want the image to be.

EDIT:

But the actual error you're getting is because `item.media_url`is a string for '<http://pbs.twimg.com/media/DlAIWwkUcAAY_3u.jpg>', so it doesn't have a url to access with `.getUrl`.

I'm unsure if it'll work, but you could try `item.media_url('footerThumbs')`

Cheers

> **Comments:**
> **username_0**: thank you, but I did try that. The solution will be in the Imager plugin, but the question is how....  
> **username_2**: I haven't used it for a long time unfortunately. Looks like Andre above is helping you. Good luck!  

---

