diff --git a/README.md b/README.md index f638a32..57ae409 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,10 @@ The image object has the following properties: - resized - dataURL - type +- width ( from jpeg exif ) +- height ( from jpeg exif ) +- name ( from jpeg exif ) + ### Multiple images with resizing @@ -63,6 +67,9 @@ When used with multiple the image object is always an array of objects with the - resized - dataURL - type +- width ( from jpeg exif ) +- height ( from jpeg exif ) +- name ( from jpeg exif ) See [demo.html](demo.html) for more concrete examples. @@ -93,7 +100,8 @@ open http://localhost:8080 ## Depends on -- angular-1.1.4 +- angular-1.2.16 +- angular-animate-1.2.16 ## Tested in following browsers: diff --git a/bower.json b/bower.json index ab65be3..baa4b9d 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "angularjs-imageupload-directive", "description": "imageupload Directive for AngularJS", - "version": "0.0.0", + "version": "0.0.2", "main": "public/javascripts/imageupload.js", "ignore": [ "**/.*", @@ -10,6 +10,8 @@ "package.json" ], "dependencies": { - "angularjs-unstable": "~1.1.4" + "angular": "1.2.16", + "angular-animate": "1.2.16", + "jsjpegmeta": "1.0.1" } } diff --git a/package.json b/package.json index bac3d94..0985c85 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angularjs-imageupload-directive", - "version": "0.0.1", + "version": "0.0.2", "description": "Upload and resize images with AngularJS. Proof of Concept.", "main": "app.js", "scripts": { @@ -8,17 +8,20 @@ }, "repository": { "type": "git", - "url": "https://github.com/Mischi/angularjs-imageupload-directive.git" + "url": "https://github.com/Zacknero/angularjs-imageupload-directive.git" }, "keywords": [ "AngularJS", "Image", "Upload", - "Resizing" + "Resizing", + "Exif" ], - "author": "Fabian Raetz", + "author": "Fabian Raetz","Zacknero" "license": "BSD", "dependencies": { - "express": "~3.1.0" + "angular": "1.2.16", + "angular-animate": "1.2.16", + "jsjpegmeta": "1.0.1" } } diff --git a/public/javascripts/imageupload.js b/public/javascripts/imageupload.js index c3c1453..baf2f64 100644 --- a/public/javascripts/imageupload.js +++ b/public/javascripts/imageupload.js @@ -1,7 +1,10 @@ angular.module('imageupload', []) + .directive('image', function($q) { 'use strict' + //require(["bower_components/jsjpegmeta/jpegmeta.js"],function(jpegmeta){}); + var URL = window.URL || window.webkitURL; var getResizeArea = function () { @@ -72,6 +75,25 @@ angular.module('imageupload', []) return deferred.promise; }; + var fileToDataInfo = function (file) { + var deferred = $q.defer(); + var reader = new FileReader(); + reader.onloadend = function(){ + + var exif = new JpegMeta.JpegFile(this.result, this.file.name); + + deferred.resolve(exif); + }; + reader.file = file; + reader.readAsBinaryString(file); + + + return deferred.promise; + + + }; + + return { restrict: 'A', @@ -80,7 +102,7 @@ angular.module('imageupload', []) resizeMaxHeight: '@?', resizeMaxWidth: '@?', resizeQuality: '@?', - resizeType: '@?', + resizeType: '@?' }, link: function postLink(scope, element, attrs, ctrl) { @@ -89,7 +111,7 @@ angular.module('imageupload', []) var dataURL = resizeImage(image, scope); imageResult.resized = { dataURL: dataURL, - type: dataURL.match(/:(.+\/.+);/)[1], + type: dataURL.match(/:(.+\/.+);/)[1] }; callback(imageResult); }); @@ -97,7 +119,6 @@ angular.module('imageupload', []) var applyScope = function(imageResult) { scope.$apply(function() { - //console.log(imageResult); if(attrs.multiple) scope.image.push(imageResult); else @@ -123,6 +144,13 @@ angular.module('imageupload', []) imageResult.dataURL = dataURL; }); + fileToDataInfo(files[i]).then(function(exif){ + imageResult.name=exif.filename; + imageResult.width=exif.general.pixelWidth.value; + imageResult.height=exif.general.pixelHeight.value; + + }); + if(scope.resizeMaxHeight || scope.resizeMaxWidth) { //resize image doResizing(imageResult, function(imageResult) { applyScope(imageResult); @@ -132,6 +160,8 @@ angular.module('imageupload', []) applyScope(imageResult); } } + + }); } };