craftcms / element-api

Create a JSON API/Feed for your elements in Craft.
MIT License
498 stars 56 forks source link

Use w/ Imager-Craft plugin? #89

Closed movingobjects closed 5 years ago

movingobjects commented 5 years ago

I'm trying to use the https://github.com/aelvan/Imager-Craft plugin to make specific image transformations, but cannot figure out how to access Imager within the element-api.php file.

Imager shows plenty of template examples, but I'm not sure how to translate template code like this into straight Element API php.

{% set image = craft.assets().one() %}
{% set transformedImage = craft.imager.transformImage(image, { width: 1000 }) %}
<img src="{{ transformedImage.url }}">

Specifically, I'm trying to access that craft.imager.transformImage function. Is this possible?

movingobjects commented 5 years ago

Thanks to @aelvan (https://github.com/aelvan/Imager-Craft/issues/198#issuecomment-426582165):

use aelvan\imager\Imager;

$transformedImage = Imager::$plugin->imager->transformImage($image, ['width' => 100]);