Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Image cropping support #8

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(cropping): Support generating interchange syntax out of the box
  • Loading branch information
nervetattoo committed Jan 28, 2015
commit 5c9e5ec93266ffd1e259df6ee0508911b33734ad
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ Craft CMS Keyteq Mediaflow plugin. Read more [Visit Mediaflow!](http://getmediaf
</noscript>
```

### Using Picturefill.js
```
If you use Interchange and have set crops for your image you can
have Mediaflow build the interchange string straightup for you by specifying the crop aliases:

```smarty
<img data-interchange="{{media.interchange(['default','large'])}}">
```
17 changes: 17 additions & 0 deletions models/Mediaflow_MediaModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,25 @@ public function getHash($coords)
return md5(implode('-', $coords));
}

/**
* Example usage:
* <img data-interchange="{{image.interchange(['default','large'])}}">
* This only works if you have specified crops with these names, and those crops have been set
*/
public function interchange($versions = array())
{
$output = array();
foreach ($versions as $name) {
$output[] = '[' . $this->versionUrl($name) . " ($name)]";
}
return implode(', ', $output);
}

public function versionUrl($name)
{
if (!isset($this->urls[$name])) {
return null;
}
$data = $this->urls[$name];
$host = craft()->plugins->getPlugin('mediaflow')->getSettings()->url;
$path = $data['media'] . '/' . $data['slug'];
Expand Down