<p>No.</p>

<p>A transform can only be applied to an <a href="http://buildwithcraft.com/docs/templating/assetfilemodel" rel="nofollow">AssetFileModel</a>, and there is no AssetFileModel for a random image.</p>

CC BY-SA 3.0
2014-06-30T19:52:45.447Z
2014-06-30T19:52:45.447Z
Marion Newlevant
<p>While <em>transforms</em> are an asset-only feature, you can get at all of the underlying image manipulation features pretty easily using the ImagesService.</p>

<pre><code>$image = craft()-&gt;images-&gt;loadImage($imageSource);
$image-&gt;setQuality($quality);
$image-&gt;resize($transform-&gt;width, $transform-&gt;height);
$image-&gt;saveAs($targetFile);
</code></pre>

CC BY-SA 3.0
2014-06-30T21:41:28.817Z
and that pretty much sums up why i love craft!!
Ben Croker
CC BY-SA 3.0
2014-07-01T14:42:45.240Z
Lovely! Looks like I just need a quick plugin to do this from Twig.
Tim Kelty
CC BY-SA 3.0
2015-05-08T12:21:59.870Z
Any pointers on how I could get the two other transform parameters to work? `mode` and `position`
peirix
CC BY-SA 3.0
2015-05-09T00:20:49.907Z
@peirix Not sure I’m following - probably worth posting as a new question.
Brandon Kelly
CC BY-SA 3.0
2015-05-10T20:01:41.483Z
@BrandonKelly I actually figured it out. What I was after was a way to send in `width`, `height`, `quality`, `mode` and `position`, like I would do with a regular assets transform. But I found that the `$image` will have both `scaleAndCrop` (which will take `position`) and `scaleToFit`.
peirix
CC BY-SA 3.0
2014-06-30T21:05:51.887Z
2014-06-30T21:05:51.887Z
Brandon Kelly
<p>Curious if I'm able to use the resizer on a random, sourced image, not coming from a field anywhere.</p>

<p>So I would just be passing a string to the path of the image.</p>

<templating>
Can I apply an image transformation to an arbitrary image (non-Assets field)?
# Can I apply an image transformation to an arbitrary image (non-Assets field)?

(Asked by: username_0 on 2014-06-30)

Curious if I'm able to use the resizer on a random, sourced image, not coming from a field anywhere.

So I would just be passing a string to the path of the image.

**Tags:** templating


---

## 2 answers

### Answer by username_2 on 2014-06-30. Score: 12 | Accepted answer

While transforms are an asset-only feature, you can get at all of the underlying image manipulation features pretty easily using the ImagesService.
$image = craft()->images->loadImage($imageSource);
$image->setQuality($quality);
$image->resize($transform->width, $transform->height);
$image->saveAs($targetFile);

> **Comments:**
> **username_3**: and that pretty much sums up why i love craft!!  
> **username_0**: Lovely! Looks like I just need a quick plugin to do this from Twig.  
> **username_4**: Any pointers on how I could get the two other transform parameters to work? `mode` and `position`  
> **username_2**: @username_4 Not sure I’m following - probably worth posting as a new question.  
> **username_4**: @BrandonKelly I actually figured it out. What I was after was a way to send in `width`, `height`, `quality`, `mode` and `position`, like I would do with a regular assets transform. But I found that the `$image` will have both `scaleAndCrop` (which will take `position`) and `scaleToFit`.  

---

### Answer by username_1 on 2014-06-30. Score: 3

No.

A transform can only be applied to an [AssetFileModel](http://buildwithcraft.com/docs/templating/assetfilemodel), and there is no AssetFileModel for a random image.


---

