From 40bd9bb20d274c8e100fca114177426ef2877fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wado=C5=84?= Date: Thu, 28 Jul 2016 18:46:48 +0200 Subject: [PATCH] Image resizer plugin class (#355) --- src/index.ts | 3 ++ src/plugins/imageresizer.ts | 77 +++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/plugins/imageresizer.ts diff --git a/src/index.ts b/src/index.ts index 3f4681b1..43bdb90a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,6 +49,7 @@ import {Hotspot} from './plugins/hotspot'; import {Httpd} from './plugins/httpd'; import {IBeacon} from './plugins/ibeacon'; import {ImagePicker} from './plugins/imagepicker'; +import {ImageResizer} from './plugins/imageresizer'; import {InAppBrowser} from './plugins/inappbrowser'; import {Insomnia} from './plugins/insomnia'; import {Keyboard} from './plugins/keyboard'; @@ -96,6 +97,7 @@ export * from './plugins/googlemaps'; export * from './plugins/httpd'; export * from './plugins/ibeacon'; export * from './plugins/imagepicker'; +export * from './plugins/imageresizer'; export * from './plugins/inappbrowser'; export * from './plugins/launchnavigator'; export * from './plugins/localnotifications'; @@ -205,6 +207,7 @@ window['IonicNative'] = { Httpd: Httpd, IBeacon: IBeacon, ImagePicker: ImagePicker, + ImageResizer: ImageResizer, InAppBrowser: InAppBrowser, Keyboard: Keyboard, LaunchNavigator: LaunchNavigator, diff --git a/src/plugins/imageresizer.ts b/src/plugins/imageresizer.ts new file mode 100644 index 00000000..a2e2f7cb --- /dev/null +++ b/src/plugins/imageresizer.ts @@ -0,0 +1,77 @@ +import { Cordova, Plugin } from './plugin'; + +export interface ImageResizerOptions { + /** + * The URI for the image on the device to get scaled + */ + uri: string; + + /** + * The width of the new image + */ + width: number; + + /** + * The height of the new image + */ + height: number; + + /** + * The name of the folder the image should be put + * (Android only) + */ + folderName?: string; + + /** + * + * Quality given as Number for the quality of the new image + * (Android and iOS only) + */ + quality?: number; + + /** + * A custom name for the file. Default name is a timestamp + * (Android and Windows only) + */ + fileName?: string; +} + +/** + * @name ImageResizer + * @description + * Cordova Plugin For Image Resize + * + * Requires plugin `info.protonet.imageresizer` - use the Ionic CLI and type in the following command: + * `ionic plugin add https://github.com/protonet/cordova-plugin-image-resizer.git` + * + * For more info, please see the https://github.com/protonet/cordova-plugin-image-resizer + * + * @usage + * ```typescript + * import { ImageResizer, ImageResizerOptions } from 'ionic-native'; + * + * let options = { + * uri: uri, + * folderName: 'Protonet', + * quality: 90, + * width: 1280, + * height: 1280 + * } as ImageResizerOptions; + * + * ImageResizer + * .resize(options) + * .then( + * (filePath: string) => { console.log('FilePath', filePath); }, + * () => { console.log('Error occured'); } + * ) + * ``` + */ +@Plugin({ + plugin: 'https://github.com/protonet/cordova-plugin-image-resizer.git', + pluginRef: 'window.ImageResizer', + repo: 'https://github.com/protonet/cordova-plugin-image-resizer' +}) +export class ImageResizer { + @Cordova() + static resize(options: ImageResizerOptions): Promise { return; } +}