Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rossmartin/cordova-plugin-instagram-assets-picker

:camera: :video_camera: :scissors: An image picker like Instagram, allowing you to crop photo and video with GPUImage.
https://github.com/rossmartin/cordova-plugin-instagram-assets-picker

Last synced: 5 days ago
JSON representation

:camera: :video_camera: :scissors: An image picker like Instagram, allowing you to crop photo and video with GPUImage.

Awesome Lists containing this project

README

        

# Cordova Instagram Assets Picker Plugin :camera: :video_camera: :scissors:

This is a cordova plugin for iOS that provides an image picker like Instagram, allowing you to crop photo and video with GPUImage.

![GIF](example.gif)

The app in the GIF shows how to use the [cordova-plugin-video-editor](https://github.com/jbavari/cordova-plugin-video-editor) and is using this plugin. [Here is a YouTube video showing more of it](https://youtu.be/U0O2gG4N0JM). [Here is the source code for the app shown in the gif and video](https://github.com/rossmartin/video-editor-ionic2).

#### I am no longer maintaining this project. PRs are welcome.

## Installation
```
cordova plugin add cordova-plugin-instagram-assets-picker
```
`InstagramAssetsPicker` will be available globally after deviceready.

To install the latest code from this repo (may be unstable) -
```
cordova plugin add https://github.com/rossmartin/cordova-plugin-instagram-assets-picker.git
```

#### You may have to update your Xcode project Header Search Paths manually
If you see `Could not locate build.xcconfig, you will need to set HEADER_SEARCH_PATHS manually.` in the CLI output when adding the plugin you will need to add an entry to your Xcode project Header Search Paths. I have this step automated but for some reason it isn't working for everyone. To do this navigate to your project Build Settings and add `"$(SRCROOT)/$(PRODUCT_NAME)/cordova-plugin-instagram-assets-picker/GPUImageHeaders"` to your Header Search Paths. See the screenshot below for reference -

![PNG](set-header-search-paths.png)

## Usage

### Show the picker with videos, photos, or all media

``` javascript
InstagramAssetsPicker.getMedia(
function(result) { // success cb
console.log('getMedia success, result: ', JSON.stringify(result, null, 2));
// result will be an object with at least a phAssetId, filePath, and type property
// you will only get the rect object when 'cropAfterSelect' is false
// the rect object is required for the cropAsset function documented below

/* example of result when the 'cropAfterSelect' option is set to false
{
phAssetId: "A1785F1A-EF0F-458C-9AF9-C439981CE0FB/L0/001",
type: "video",
rect: {
Width: 0.5625000293366611,
Height: 0.9999999823048711,
Y: 0,
X: 0.2496093880181434
},
filePath: "file:///Users/rossmartin/Library/Developer/CoreSimulator/Devices/6465544C-C262-4EA8-BA7C-8BAB4AB98597/data/Media/DCIM/100APPLE/IMG_0006.m4v"
}
*/
},
function(err) { // error cb
console.log('getMedia error, err: ', err);
},
{ // options
type: 'video', // accepts 'photo', 'video', or 'all' - defaults to all
cropAfterSelect: false, // see the note above for when this is false - defaults to false
showGrid: false // determines whether to show the grid for cropping - defaults to false
}
);
```

#### A note about the cropAfterSelect option with getMedia
The reason this option exists is to provide a better user experience. It takes time to crop an asset with GPUImage so in most cases for a better UX you'll want to call `cropAsset` later with the result from the `getMedia` function. This also allows showing your own UI loading indicator while the cropping is being performed.

#### A note about cropping using getMedia or cropAsset
The iOS simulator will not finish a crop using `getMedia` (with `cropAfterSelect` set to `true`) or `cropAsset`. It works fine on a device. I will be looking into why it doesn't work on the simulator.

### Crop a media asset from the device library
```javascript
InstagramAssetsPicker.cropAsset(
function(result) { // success cb
// result is an object with a filePath and type property
console.log('cropAsset success, result: ', result);
/* example of result
{
type: "video",
filePath: "file:///Users/rossmartin/Library/Developer/CoreSimulator/Devices/6465544C-C262-4EA8-BA7C-8BAB4AB98597/data/Media/DCIM/100APPLE/IMG_0006.m4v"
}
*/
},
function(err) { // error cb
console.log('cropAsset error, err: ', err);
},
{ // options, both properties below are required
phAssetId: "A1785F1A-EF0F-458C-9AF9-C439981CE0FB/L0/001",
rect: {
Width: 1,
Height: 0.5625,
Y: 0.249609375,
X: 0
}
}
);
```

## Author

[Ross Martin](https://github.com/rossmartin)

## Reference

[InstagramAssetsPicker](https://github.com/Jexbat/InstagramAssetsPicker) (Modified by me to add features for this plugin and subtle improvements.)

## License

[The MIT License (MIT)](http://www.opensource.org/licenses/mit-license.html)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.