Skip to content

Instantly share code, notes, and snippets.

@facultymatt
Created October 10, 2013 19:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save facultymatt/6923690 to your computer and use it in GitHub Desktop.
Save facultymatt/6923690 to your computer and use it in GitHub Desktop.
Example image controller
function ImagesController($scope, $routeParams, $location, Global) {
// get global settings
$scope.global = Global;
// set filepicker key
filepicker.setKey('Akpol0G7ZQ7ODgRPSZPJRz');
// define our empty image object
$scope.newImage = {};
/**
* Add an image to a projects Images array
* @note needs to be saved to work
*
*/
$scope.addImageToDest = function(image, dest) {
// we copy the image to avoid binding issues
destCopy = angular.copy(image);
// reset he image
image = null;
// add to dest array
dest.push(destCopy);
return image;
};
/**
* Remove an image from projects Images Array
* @note needs to be saved to work
*
*/
$scope.deleteImageFromDest = function(image, dest) {
console.log(Array.isArray(dest));
console.log(dest);
// for an array we need to splice
if(typeof dest === 'object' && Array.isArray(dest)) {
dest.splice(dest.indexOf(image), 1);
} else {
dest = {};
}
console.log(dest);
return dest;
};
/**
* Pick and image and assign to dest object, cropping to specific w and h
* @note the original image is deleted, and the cropped image is returned.
*
*/
$scope.pickImage = function(dest, options) {
// set default options
var defaultOptions = {
fit: 'crop',
quality: 100
}
options = angular.extend(options, defaultOptions);
console.log(options);
if(!dest.src) dest.src = '';
if(!dest.original) dest.original = '';
console.log(dest);
filepicker.pick(function(InkBlob){
console.log(InkBlob.url);
dest.original = InkBlob.url;
filepicker.convert(InkBlob, options, function(new_InkBlob){
console.log(new_InkBlob.url);
dest.src = new_InkBlob.url;
$scope.$apply();
});
});
return dest;
};
/**
* Pick and image and assign to dest object, cropping to specific w and h
* @note the original image is deleted, and the cropped image is returned.
*
*/
$scope.pickManyImages = function(destArray, options) {
// set default options
var defaultOptions = {
fit: 'crop',
quality: 100
}
options = angular.extend(options, defaultOptions);
console.log(options);
if(!destArray) destArray = [];
console.log(destArray);
filepicker.pickMultiple(function(InkBlobs){
var blobs = InkBlobs;
destArray = JSON.stringify(blobs);
console.log(destArray);
return destArray;
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment