Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 12 down vote accepted

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);
share|improve this answer
3  
and that pretty much sums up why i love craft!! –  Ben Croker Jun 30 '14 at 21:41
    
Lovely! Looks like I just need a quick plugin to do this from Twig. –  Tim Kelty Jul 1 '14 at 14:42
    
Any pointers on how I could get the two other transform parameters to work? mode and position –  peirix May 8 at 12:21
    
@peirix Not sure I’m following - probably worth posting as a new question. –  Brandon Kelly May 9 at 0:20
    
@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 May 10 at 20:01

No.

A transform can only be applied to an AssetFileModel, and there is no AssetFileModel for a random image.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.