PHPackages                             dakzilla/intervention-image-helper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. dakzilla/intervention-image-helper

AbandonedArchivedMagento2-module[Image &amp; Media](/categories/media)

dakzilla/intervention-image-helper
==================================

Intervention Image helper for Magento 2

1.0.6(6y ago)810.7k↓33.3%4[1 issues](https://github.com/dakzilla/magento2-intervention-image-helper/issues)MITPHPPHP &gt;=7.0.0

Since Mar 12Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dakzilla/magento2-intervention-image-helper)[ Packagist](https://packagist.org/packages/dakzilla/intervention-image-helper)[ RSS](/packages/dakzilla-intervention-image-helper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (8)Used By (0)

Intervention Image helper for Magento 2
=======================================

[](#intervention-image-helper-for-magento-2)

A useful template helper for applying transformations to images in Magento 2 using the [Intervention Image](http://image.intervention.io) library.

Installation
------------

[](#installation)

`composer require dakzilla/intervention-image-helper`

`php bin/magento setup:upgrade`

Features
--------

[](#features)

- The image helper can be called from any front-end `.phtml` template. No need to create a custom block!
- All of the transformation methods can be chained
- By using an @var [DocComment](https://phpdoc.org/docs/latest/references/phpdoc/tags/var.html) as shown in the example below, your IDE will show autocompletion and documentation hints for each method
- The images are cached automatically on creation, and are loaded from cache on every subsequent call
- Ability to set JPEG quality directly in template
- Plays well with other image manipulation/optimization modules

Usage
-----

[](#usage)

### Transforming an image from a template

[](#transforming-an-image-from-a-template)

Call the image helper from any front-end (.phtml) template using this code:

```

```

You can now call the `make` method to a relative image path or an image URL

```
$image = $imageHelper->make('test/Pineapple.jpg')

Will resolve and load the file at /path/to/your/site/pub/media/test/Pineapple.jpg

```

Then, you can chain the desired transformation methods, and finally call the `get` method to get the http link to the cached image:

```
$imageUrl = $image->flip()
    ->invert()
    ->resize(350, null, function ($constraint) {
        $constraint->aspectRatio();
    })
    ->get();

# Will return http://mysite.com/media/cache/dakzilla_intervention//myimage.jpg

```

Or, you can do all of these at once with a short, chained syntax:

```
