diff --git a/bower.json b/bower.json index 07f9859..079f2ea 100644 --- a/bower.json +++ b/bower.json @@ -1,8 +1,8 @@ { - "name": "blueimp-load-image", + "name": "blueimp-load-image-nodejs", "version": "1.13.0", "title": "JavaScript Load Image", - "description": "JavaScript Load Image is a library to load images provided as File or Blob objects or via URL. It returns an optionally scaled and/or cropped HTML img or canvas element. It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing.", + "description": "JavaScript Load Image is a library to load images provided as File or Blob objects or via URL. It returns an optionally scaled and/or cropped HTML img or canvas element. It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing. This version is with nodejs support for canvas and image.", "keywords": [ "javascript", "load", diff --git a/js/load-image-exif-map.js b/js/load-image-exif-map.js index 8811a52..c3cafa4 100644 --- a/js/load-image-exif-map.js +++ b/js/load-image-exif-map.js @@ -21,7 +21,7 @@ define(['load-image', 'load-image-exif'], factory); } else { // Browser globals: - factory(window.loadImage); + factory(globalWindow.loadImage); } }(function (loadImage) { 'use strict'; diff --git a/js/load-image-exif.js b/js/load-image-exif.js index 347369b..4969314 100644 --- a/js/load-image-exif.js +++ b/js/load-image-exif.js @@ -19,7 +19,7 @@ define(['load-image', 'load-image-meta'], factory); } else { // Browser globals: - factory(window.loadImage); + factory(globalWindow.loadImage); } }(function (loadImage) { 'use strict'; diff --git a/js/load-image-ios.js b/js/load-image-ios.js index 6f8e4fd..1a3921a 100644 --- a/js/load-image-ios.js +++ b/js/load-image-ios.js @@ -22,14 +22,14 @@ define(['load-image'], factory); } else { // Browser globals: - factory(window.loadImage); + factory(globalWindow.loadImage); } }(function (loadImage) { 'use strict'; // Only apply fixes on the iOS platform: - if (!window.navigator || !window.navigator.platform || - !(/iP(hone|od|ad)/).test(window.navigator.platform)) { + if (!globalWindow.navigator || !globalWindow.navigator.platform || + !(/iP(hone|od|ad)/).test(globalWindow.navigator.platform)) { return; } diff --git a/js/load-image-meta.js b/js/load-image-meta.js index d808508..c0d5748 100644 --- a/js/load-image-meta.js +++ b/js/load-image-meta.js @@ -23,12 +23,12 @@ define(['load-image'], factory); } else { // Browser globals: - factory(window.loadImage); + factory(globalWindow.loadImage); } }(function (loadImage) { 'use strict'; - var hasblobSlice = window.Blob && (Blob.prototype.slice || + var hasblobSlice = globalWindow.Blob && (Blob.prototype.slice || Blob.prototype.webkitSlice || Blob.prototype.mozSlice); loadImage.blobSlice = hasblobSlice && function () { @@ -54,7 +54,7 @@ // 256 KiB should contain all EXIF/ICC/IPTC segments: maxMetaDataSize = options.maxMetaDataSize || 262144, data = {}, - noMetaData = !(window.DataView && file && file.size >= 12 && + noMetaData = !(globalWindow.DataView && file && file.size >= 12 && file.type === 'image/jpeg' && loadImage.blobSlice); if (noMetaData || !loadImage.readFile( loadImage.blobSlice.call(file, 0, maxMetaDataSize), diff --git a/js/load-image-orientation.js b/js/load-image-orientation.js index f0a32fa..ef6f232 100644 --- a/js/load-image-orientation.js +++ b/js/load-image-orientation.js @@ -18,7 +18,7 @@ define(['load-image'], factory); } else { // Browser globals: - factory(window.loadImage); + factory(globalWindow.loadImage); } }(function (loadImage) { 'use strict'; diff --git a/js/load-image.js b/js/load-image.js index adb63a9..9ca3680 100644 --- a/js/load-image.js +++ b/js/load-image.js @@ -1,5 +1,5 @@ /* - * JavaScript Load Image 1.10.0 + * JavaScript Load Image 1.10.0 with nodejs support for canvas and image * https://github.com/blueimp/JavaScript-Load-Image * * Copyright 2011, Sebastian Tschan @@ -18,11 +18,16 @@ // Loads an image for a given File object. // Invokes the callback with an img or optional canvas // element (if supported by the browser) as parameter: - var loadImage = function (file, callback, options) { - var img = document.createElement('img'), + globalWindow.loadImage = function (file, callback, options) { + var img = typeof document != 'undefined' ? document.createElement('img') : new globalWindow.canvas.Image, url, oUrl; - img.onerror = callback; + img.onerror = function () { + console.log("img load error"); + if (callback) { + callback(); + } + }; img.onload = function () { if (oUrl && !(options && options.noRevoke)) { loadImage.revokeObjectURL(oUrl); @@ -63,9 +68,9 @@ }, // The check for URL.revokeObjectURL fixes an issue with Opera 12, // which provides URL.createObjectURL but doesn't properly implement it: - urlAPI = (window.createObjectURL && window) || - (window.URL && URL.revokeObjectURL && URL) || - (window.webkitURL && webkitURL); + globalWindow.urlAPI = (globalWindow.createObjectURL && globalWindow) || + (globalWindow.URL && URL.revokeObjectURL && URL) || + (globalWindow.webkitURL && webkitURL); loadImage.isInstanceOf = function (type, obj) { // Cross-frame instanceof check @@ -151,7 +156,7 @@ // object is passed as image, else the scaled image: loadImage.scale = function (img, options) { options = options || {}; - var canvas = document.createElement('canvas'), + var canvas = typeof document != 'undefined' ? document.createElement('canvas') : new globalWindow.canvas(1,1), useCanvas = img.getContext || (loadImage.hasCanvasOption(options) && canvas.getContext), width = img.naturalWidth || img.width, @@ -279,7 +284,7 @@ // invokes the callback with the event object (load or error). // The result can be read via event.target.result: loadImage.readFile = function (file, callback, method) { - if (window.FileReader) { + if (globalWindow.FileReader) { var fileReader = new FileReader(); fileReader.onload = fileReader.onerror = callback; method = method || 'readAsDataURL'; diff --git a/package.json b/package.json index bde2fb2..6a5bcd6 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "blueimp-load-image", + "name": "blueimp-load-image-nodejs", "version": "1.13.0", "title": "JavaScript Load Image", "description": "JavaScript Load Image is a library to load images provided as File or Blob objects or via URL. It returns an optionally scaled and/or cropped HTML img or canvas element. It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing.", @@ -20,22 +20,8 @@ "thumbnail", "resizing" ], - "homepage": "https://github.com/blueimp/JavaScript-Load-Image", - "author": { - "name": "Sebastian Tschan", - "url": "https://blueimp.net" - }, - "maintainers": [ - { - "name": "Sebastian Tschan", - "url": "https://blueimp.net" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/blueimp/JavaScript-Load-Image.git" - }, - "bugs": "https://github.com/blueimp/JavaScript-Load-Image/issues", + "homepage": "https://github.com/brownbag-it/JavaScript-Load-Image", + "bugs": "https://github.com/brownbag-it/JavaScript-Load-Image/issues", "licenses": [ { "type": "MIT",