<commit_before># Imgix plugin for Craft CMS

Imgix is awesome

![Screenshot](resources/icon.png)

## Installation

To install Imgix, follow these steps:

1. Download & unzip the file and place the `imgix` directory into your `craft/plugins` directory
2. Install plugin in the Craft Control Panel under Settings > Plugins
4. The plugin folder should be named `imgix` for Craft to see it.

Imgix works on Craft 2.4.x and Craft 2.5.x.

## Configuring Imgix

Copy `config.php` into Crafts `config` folder and rename it to `imgix.php`.

Then map your Asset Source handle to your Imgix domain, according to the example.

This plugin will lookup the Asset image's source handle, and figure out which Imgix domain to use. If a URL string is passed, it will use the first domain in the config file.

## Using Imgix

```twig
{% set transforms = [
    {
        width: 400,
        height: 300
    },
    {
        width: 940,
        height: 520
    },
    {
        width: 1400,
    },
] %}

{% set firstImage = craft.imgix.transformImage( asset, { width: 400, height: 350 }) %}
{% set secondImage = craft.imgix.transformImage( asset, transforms) %}

{# Image tag #}
{{ firstImage.img() }}

{# Image tag w/ srcset + tag attributes #}
{{ secondImage.srcset({ width: 700 }) }}

{# See transformed results #}
{{ dump(secondImage.transformed) }}
```

## Imgix Roadmap

- Clean it up
- Add documentation
- Look into improving srcset/API

## Imgix Changelog

### 1.0.0 -- 2017.04.03

* Initial release

Brought to you by [Superbig](https://superbig.co)<commit_msg>Update readme with Element API example<commit_after># Imgix plugin for Craft CMS

Imgix is awesome

![Screenshot](resources/icon.png)

## Installation

To install Imgix, follow these steps:

1. Download & unzip the file and place the `imgix` directory into your `craft/plugins` directory
2. Install plugin in the Craft Control Panel under Settings > Plugins
4. The plugin folder should be named `imgix` for Craft to see it.

Imgix works on Craft 2.4.x and Craft 2.5.x.

## Configuring Imgix

Copy `config.php` into Crafts `config` folder and rename it to `imgix.php`.

Then map your Asset Source handle to your Imgix domain, according to the example.

This plugin will lookup the Asset image's source handle, and figure out which Imgix domain to use. If a URL string is passed, it will use the first domain in the config file.

## Using Imgix

```twig
{% set transforms = [
    {
        width: 400,
        height: 300
    },
    {
        width: 940,
        height: 520
    },
    {
        width: 1400,
    },
] %}

{% set firstImage = craft.imgix.transformImage( asset, { width: 400, height: 350 }) %}
{% set secondImage = craft.imgix.transformImage( asset, transforms) %}

{# Image tag #}
{{ firstImage.img() }}

{# Get url for the first image #}
{{ firstImage.url }} or {{ firstImage.getUrl() }}

{# Image tag w/ srcset + tag attributes #}
{{ secondImage.srcset({ width: 700 }) }}

{# See transformed results #}
{{ dump(secondImage.transformed) }}
```

To use with Element API, you can call the service directly:

```php
<?php
namespace Craft;

return [
    'endpoints' => [
        'news.json' => [
            'elementType' => ElementType::Entry,
            'criteria' => ['section' => 'news'],
            'transformer' => function(EntryModel $entry) {
                $asset = $entry->featuredImage->first();
                $featuredImage = craft()->imgix->transformImage( $asset, [ 'width' => 400, 'height' => 350 ]);
                return [
                    'title' => $entry->title,
                    'url' => $entry->url,
                    'jsonUrl' => UrlHelper::getUrl("news/{$entry->id}.json"),
                    'summary' => $entry->summary,
                    'featuredImage' => $featuredImage,
                ];
            },
        ],
    ]
];
```

## Imgix Roadmap

- Clean it up
- Add documentation
- Look into improving srcset/API

## Imgix Changelog

### 1.0.0 -- 2017.04.03

* Initial release

Brought to you by [Superbig](https://superbig.co)
{'fraction_non_alphanumeric': 0.12465923172242875, 'fraction_numerical': 0.022800495662949196, 'mean_word_length': 2.7790262172284645, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 26, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3120193', 'n_tokens_mistral': 1333, 'n_tokens_neox': 1215, 'n_words': 437}