Skip to content

Commit 29138ce

Browse files
committed
Start of XMP reading.
1 parent 4ed15dc commit 29138ce

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

js/load-image-xmp.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
; (function (factory) {
2+
'use strict'
3+
if (typeof define === 'function' && define.amd) {
4+
// Register as an anonymous AMD module:
5+
define(['./load-image', './load-image-meta'], factory)
6+
} else if (typeof module === 'object' && module.exports) {
7+
factory(require('./load-image'), require('./load-image-meta'))
8+
} else {
9+
// Browser globals:
10+
factory(window.loadImage)
11+
}
12+
} (function (loadImage) {
13+
'use strict'
14+
15+
loadImage.parseXmpData = function (dataView, offset, length, data, options) {
16+
if (options.disableExif) {
17+
return;
18+
}
19+
20+
// Check for the ASCII code for "http" (0x68747470). Note that the actual XMP identifier is quite long: "http://ns.adobe.com/xap/1.0/\x00"
21+
var arrIdentifier = [];
22+
var offsetNamespace = 4;
23+
var lengthNamespace = 29;
24+
for (var i = 0; i < lengthNamespace; i++) {
25+
arrIdentifier[i] = String.fromCharCode(dataView.getInt8(offset + offsetNamespace + i));
26+
}
27+
28+
var identifier = arrIdentifier.join("");
29+
if (identifier !== "http://ns.adobe.com/xap/1.0/\0") {
30+
// No XMP data.
31+
return;
32+
}
33+
34+
var offsetLp = 2; // Offset to the packet length field.
35+
var xmpLength = dataView.getUint16(offset + offsetLp);
36+
37+
var lengthLp = 2;
38+
xmpLength -= (lengthLp + lengthNamespace); // The packet length is a little misleading it includes the length of Lp and Namespace, remove those two to get the actual packet length.
39+
40+
var maxPacketLength = 65503;
41+
if (maxPacketLength < xmpLength){
42+
return;
43+
}
44+
}
45+
46+
loadImage.metaDataParsers.jpeg[0xffe1].push(loadImage.parseXmpData);
47+
}))

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"meta",
2020
"exif",
2121
"thumbnail",
22-
"resizing"
22+
"resizing",
23+
"xmp"
2324
],
2425
"homepage": "https://github.com/blueimp/JavaScript-Load-Image",
2526
"author": {
@@ -37,7 +38,7 @@
3738
},
3839
"scripts": {
3940
"test": "standard *.js js/*.js test/*.js && mocha-phantomjs test/index.html",
40-
"build": "cd js && uglifyjs load-image.js load-image-orientation.js load-image-meta.js load-image-exif.js load-image-exif-map.js -c -m -o load-image.all.min.js --source-map load-image.all.min.js.map",
41+
"build": "cd js && uglifyjs load-image.js load-image-orientation.js load-image-meta.js load-image-exif.js load-image-exif-map.js load-image-xmp.js -c -m -o load-image.all.min.js --source-map load-image.all.min.js.map",
4142
"preversion": "npm test",
4243
"version": "npm run build && git add -A js",
4344
"postversion": "git push --tags origin master master:gh-pages && npm publish"

0 commit comments

Comments
 (0)