Skip to content

Commit

Permalink
Merge pull request #20 from rokka-io/19-subject-area
Browse files Browse the repository at this point in the history
Fix #19: add support for subject area
  • Loading branch information
pstadler authored Mar 7, 2017
2 parents ada0ea6 + f1dc70b commit c11ac03
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,43 @@ rokka.sourceimages.delete('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
.catch(function(err) {});
```

#### User metadata
### Dynamic metadata

See [the dynamic metadata documentation](https://rokka.io/documentation/references/dynamic-metadata.html) for
more information.

#### rokka.sourceimages.setSubjectArea(organization, hash, coords) → Promise

Set the subject area of a source image.

The [subject area of an image](https://rokka.io/documentation/references/dynamic-metadata.html#subject-area) is
used when applying the [crop operation](https://rokka.io/documentation/references/operations.html#crop) with the
`auto` anchor to center the cropping box around the subject area.

```js
rokka.sourceimages.setSubjectArea('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', {
x: 100,
y: 100,
width: 50,
height: 50
}).then(function(result) {})
.catch(function(err) {});
```

#### rokka.sourceimages.removeSubjectArea(organization, hash) → Promise

Removes the subject area from a source image.

```js
rokka.sourceimages.removeSubjectArea('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
.then(function(result) {})
.catch(function(err) {});
```

### User metadata

See [the user metadata documentation](https://rokka.io/documentation/references/user-metadata.html)
for more information.

#### rokka.sourceimages.meta.add(organization, hash, data) → Promise

Expand Down
55 changes: 54 additions & 1 deletion src/apis/sourceimages.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,60 @@ export default (state) => {
};

/**
* #### User metadata
* ### Dynamic metadata
*
* See [the dynamic metadata documentation](https://rokka.io/documentation/references/dynamic-metadata.html) for
* more information.
*/

/**
* Set the subject area of a source image.
*
* The [subject area of an image](https://rokka.io/documentation/references/dynamic-metadata.html#subject-area) is
* used when applying the [crop operation](https://rokka.io/documentation/references/operations.html#crop) with the
* `auto` anchor to center the cropping box around the subject area.
*
* ```js
* rokka.sourceimages.setSubjectArea('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a', {
* x: 100,
* y: 100,
* width: 50,
* height: 50
* }).then(function(result) {})
* .catch(function(err) {});
* ```
*
* @param {string} organization name
* @param {string} hash image hash
* @param {{width: number, height: number, x: number, y: number}} coords x, y starting from top left
* @returns {Promise}
*/
sourceimages.setSubjectArea = (organization, hash, coords) => {
return state.request('PUT', `sourceimages/${organization}/${hash}/meta/dynamic/SubjectArea`, coords);
};

/**
* Removes the subject area from a source image.
*
* ```js
* rokka.sourceimages.removeSubjectArea('myorg', 'c421f4e8cefe0fd3aab22832f51e85bacda0a47a')
* .then(function(result) {})
* .catch(function(err) {});
* ```
*
* @param {string} organization
* @param {string} hash
* @return {Promise}
*/
sourceimages.removeSubjectArea = (organization, hash) => {
return state.request('DELETE', `sourceimages/${organization}/${hash}/meta/dynamic/SubjectArea`);
};

/**
* ### User metadata
*
* See [the user metadata documentation](https://rokka.io/documentation/references/user-metadata.html)
* for more information.
*/

/**
Expand Down

0 comments on commit c11ac03

Please sign in to comment.