From f1dc70bb7dbb6cdebffaceee3e757bd22b655824 Mon Sep 17 00:00:00 2001 From: Michael Weibel Date: Mon, 6 Mar 2017 10:16:45 +0100 Subject: [PATCH] Fix #19: add support for subject area --- README.md | 38 ++++++++++++++++++++++++++- src/apis/sourceimages.js | 55 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c66707e..e0f9478 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/apis/sourceimages.js b/src/apis/sourceimages.js index 3fbb03b..d1a34c2 100644 --- a/src/apis/sourceimages.js +++ b/src/apis/sourceimages.js @@ -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. */ /**