forked from petalvlad/angular-canvas-ext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif.min.js
9 lines (9 loc) · 12.6 KB
/
exif.min.js
1
2
3
4
5
6
7
8
9
/** @license
* JavaScript libarary for reading EXIF image metadata
*
* https://github.com/jseidelin/exif-js
*
* Copyright (c) 2008 Jacob Seidelin
* Released under the MIT license
*/
var BinaryFile=function(a,b,c){var d=a,e=b||0,f=0;this.getRawData=function(){return d},"string"==typeof a?(f=c||d.length,this.getByteAt=function(a){return 255&d.charCodeAt(a+e)},this.getBytesAt=function(a,b){for(var c=[],f=0;b>f;f++)c[f]=255&d.charCodeAt(a+f+e);return c}):"unknown"==typeof a&&(f=c||IEBinary_getLength(d),this.getByteAt=function(a){return IEBinary_getByteAt(d,a+e)},this.getBytesAt=function(a,b){return new VBArray(IEBinary_getBytesAt(d,a+e,b)).toArray()}),this.getLength=function(){return f},this.getSByteAt=function(a){var b=this.getByteAt(a);return b>127?b-256:b},this.getShortAt=function(a,b){var c=b?(this.getByteAt(a)<<8)+this.getByteAt(a+1):(this.getByteAt(a+1)<<8)+this.getByteAt(a);return 0>c&&(c+=65536),c},this.getSShortAt=function(a,b){var c=this.getShortAt(a,b);return c>32767?c-65536:c},this.getLongAt=function(a,b){var c=this.getByteAt(a),d=this.getByteAt(a+1),e=this.getByteAt(a+2),f=this.getByteAt(a+3),g=b?(((c<<8)+d<<8)+e<<8)+f:(((f<<8)+e<<8)+d<<8)+c;return 0>g&&(g+=4294967296),g},this.getSLongAt=function(a,b){var c=this.getLongAt(a,b);return c>2147483647?c-4294967296:c},this.getStringAt=function(a,b){for(var c=[],d=this.getBytesAt(a,b),e=0;b>e;e++)c[e]=String.fromCharCode(d[e]);return c.join("")},this.getCharAt=function(a){return String.fromCharCode(this.getByteAt(a))},this.toBase64=function(){return window.btoa(d)},this.fromBase64=function(a){d=window.atob(a)}},BinaryAjax=function(){function a(){var a=null;return window.ActiveXObject?a=new ActiveXObject("Microsoft.XMLHTTP"):window.XMLHttpRequest&&(a=new XMLHttpRequest),a}function b(b,c,d){var e=a();e?(c&&("undefined"!=typeof e.onload?e.onload=function(){"200"==e.status?c(this):d&&d(),e=null}:e.onreadystatechange=function(){4==e.readyState&&("200"==e.status?c(this):d&&d(),e=null)}),e.open("HEAD",b,!0),e.send(null)):d&&d()}function c(b,c,d,e,f,g){var h=a();if(h){var i=0;e&&!f&&(i=e[0]);var j=0;e&&(j=e[1]-e[0]+1),c&&("undefined"!=typeof h.onload?h.onload=function(){"200"==h.status||"206"==h.status||"0"==h.status?(h.binaryResponse=new BinaryFile(h.responseText,i,j),h.fileSize=g||h.getResponseHeader("Content-Length"),c(h)):d&&d(),h=null}:h.onreadystatechange=function(){if(4==h.readyState){if("200"==h.status||"206"==h.status||"0"==h.status){var a={status:h.status,binaryResponse:new BinaryFile("unknown"==typeof h.responseBody?h.responseBody:h.responseText,i,j),fileSize:g||h.getResponseHeader("Content-Length")};c(a)}else d&&d();h=null}}),h.open("GET",b,!0),h.overrideMimeType&&h.overrideMimeType("text/plain; charset=x-user-defined"),e&&f&&h.setRequestHeader("Range","bytes="+e[0]+"-"+e[1]),h.setRequestHeader("If-Modified-Since","Sat, 1 Jan 1970 00:00:00 GMT"),h.send(null)}else d&&d()}return function(a,d,e,f){f?b(a,function(b){var g,h,i=parseInt(b.getResponseHeader("Content-Length"),10),j=b.getResponseHeader("Accept-Ranges");g=f[0],f[0]<0&&(g+=i),h=g+f[1]-1,c(a,d,e,[g,h],"bytes"==j,i)}):c(a,d,e)}}();document.write("<script type='text/vbscript'>\r\nFunction IEBinary_getByteAt(strBinary, iOffset)\r\n IEBinary_getByteAt = AscB(MidB(strBinary, iOffset + 1, 1))\r\nEnd Function\r\nFunction IEBinary_getBytesAt(strBinary, iOffset, iLength)\r\n Dim aBytes()\r\n ReDim aBytes(iLength - 1)\r\n For i = 0 To iLength - 1\r\n aBytes(i) = IEBinary_getByteAt(strBinary, iOffset + i)\r\n Next\r\n IEBinary_getBytesAt = aBytes\r\nEnd Function\r\nFunction IEBinary_getLength(strBinary)\r\n IEBinary_getLength = LenB(strBinary)\r\nEnd Function\r\n</script>\r\n");var EXIF=function(){function a(a){return!!a.exifdata}function b(a,b){function d(d){var e=c(d);a.exifdata=e||{},b&&b.call(a)}if(a instanceof Image)BinaryAjax(a.src,function(a){d(a.binaryResponse)});else if(window.FileReader&&a instanceof window.File){var e=new FileReader;e.onload=function(a){d(new BinaryFile(a.target.result))},e.readAsBinaryString(a)}}function c(a){if(255!=a.getByteAt(0)||216!=a.getByteAt(1))return!1;for(var b,c=2,d=a.getLength();d>c;){if(255!=a.getByteAt(c))return l&&console.log("Not a valid marker at offset "+c+", found: "+a.getByteAt(c)),!1;if(b=a.getByteAt(c+1),22400==b)return l&&console.log("Found 0xFFE1 marker"),f(a,c+4,a.getShortAt(c+2,!0)-2);if(225==b)return l&&console.log("Found 0xFFE1 marker"),f(a,c+4,a.getShortAt(c+2,!0)-2);c+=2+a.getShortAt(c+2,!0)}}function d(a,b,c,d,f){var g,h,i,j=a.getShortAt(c,f),k={};for(i=0;j>i;i++)g=c+12*i+2,h=d[a.getShortAt(g,f)],!h&&l&&console.log("Unknown tag: "+a.getShortAt(g,f)),k[h]=e(a,g,b,c,f);return k}function e(a,b,c,d,e){var f,g,h,i,j,k,l=a.getShortAt(b+2,e),m=a.getLongAt(b+4,e),n=a.getLongAt(b+8,e)+c;switch(l){case 1:case 7:if(1==m)return a.getByteAt(b+8,e);for(f=m>4?n:b+8,g=[],i=0;m>i;i++)g[i]=a.getByteAt(f+i);return g;case 2:return f=m>4?n:b+8,a.getStringAt(f,m-1);case 3:if(1==m)return a.getShortAt(b+8,e);for(f=m>2?n:b+8,g=[],i=0;m>i;i++)g[i]=a.getShortAt(f+2*i,e);return g;case 4:if(1==m)return a.getLongAt(b+8,e);g=[];for(var i=0;m>i;i++)g[i]=a.getLongAt(n+4*i,e);return g;case 5:if(1==m)return j=a.getLongAt(n,e),k=a.getLongAt(n+4,e),h=new Number(j/k),h.numerator=j,h.denominator=k,h;for(g=[],i=0;m>i;i++)j=a.getLongAt(n+8*i,e),k=a.getLongAt(n+4+8*i,e),g[i]=new Number(j/k),g[i].numerator=j,g[i].denominator=k;return g;case 9:if(1==m)return a.getSLongAt(b+8,e);for(g=[],i=0;m>i;i++)g[i]=a.getSLongAt(n+4*i,e);return g;case 10:if(1==m)return a.getSLongAt(n,e)/a.getSLongAt(n+4,e);for(g=[],i=0;m>i;i++)g[i]=a.getSLongAt(n+8*i,e)/a.getSLongAt(n+4+8*i,e);return g}}function f(a,b){if("Exif"!=a.getStringAt(b,4))return l&&console.log("Not valid EXIF data! "+a.getStringAt(b,4)),!1;var c,e,f,g,h,i=b+6;if(18761==a.getShortAt(i))c=!1;else{if(19789!=a.getShortAt(i))return l&&console.log("Not valid TIFF data! (no 0x4949 or 0x4D4D)"),!1;c=!0}if(42!=a.getShortAt(i+2,c))return l&&console.log("Not valid TIFF data! (no 0x002A)"),!1;if(8!=a.getLongAt(i+4,c))return l&&console.log("Not valid TIFF data! (First offset not 8)",a.getShortAt(i+4,c)),!1;if(e=d(a,i,i+8,n,c),e.ExifIFDPointer){g=d(a,i,i+e.ExifIFDPointer,m,c);for(f in g){switch(f){case"LightSource":case"Flash":case"MeteringMode":case"ExposureProgram":case"SensingMethod":case"SceneCaptureType":case"SceneType":case"CustomRendered":case"WhiteBalance":case"GainControl":case"Contrast":case"Saturation":case"Sharpness":case"SubjectDistanceRange":case"FileSource":g[f]=p[f][g[f]];break;case"ExifVersion":case"FlashpixVersion":g[f]=String.fromCharCode(g[f][0],g[f][1],g[f][2],g[f][3]);break;case"ComponentsConfiguration":g[f]=p.Components[g[f][0]]+p.Components[g[f][1]]+p.Components[g[f][2]]+p.Components[g[f][3]]}e[f]=g[f]}}if(e.GPSInfoIFDPointer){h=d(a,i,i+e.GPSInfoIFDPointer,o,c);for(f in h){switch(f){case"GPSVersionID":h[f]=h[f][0]+"."+h[f][1]+"."+h[f][2]+"."+h[f][3]}e[f]=h[f]}}return e}function g(c,d){return c instanceof Image&&!c.complete?!1:(a(c)?d&&d.call(c):b(c,d),!0)}function h(b,c){return a(b)?b.exifdata[c]:void 0}function i(b){if(!a(b))return{};var c,d=b.exifdata,e={};for(c in d)d.hasOwnProperty(c)&&(e[c]=d[c]);return e}function j(b){if(!a(b))return"";var c,d=b.exifdata,e="";for(c in d)d.hasOwnProperty(c)&&(e+="object"==typeof d[c]?d[c]instanceof Number?c+" : "+d[c]+" ["+d[c].numerator+"/"+d[c].denominator+"]\r\n":c+" : ["+d[c].length+" values]\r\n":c+" : "+d[c]+"\r\n");return e}function k(a){return c(a)}var l=!1,m={36864:"ExifVersion",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37500:"MakerNote",37510:"UserComment",40964:"RelatedSoundFile",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37520:"SubsecTime",37521:"SubsecTimeOriginal",37522:"SubsecTimeDigitized",33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"ISOSpeedRatings",34856:"OECF",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBias",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37396:"SubjectArea",37386:"FocalLength",41483:"FlashEnergy",41484:"SpatialFrequencyResponse",41486:"FocalPlaneXResolution",41487:"FocalPlaneYResolution",41488:"FocalPlaneResolutionUnit",41492:"SubjectLocation",41493:"ExposureIndex",41495:"SensingMethod",41728:"FileSource",41729:"SceneType",41730:"CFAPattern",41985:"CustomRendered",41986:"ExposureMode",41987:"WhiteBalance",41988:"DigitalZoomRation",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",40965:"InteroperabilityIFDPointer",42016:"ImageUniqueID"},n={256:"ImageWidth",257:"ImageHeight",34665:"ExifIFDPointer",34853:"GPSInfoIFDPointer",40965:"InteroperabilityIFDPointer",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",274:"Orientation",277:"SamplesPerPixel",284:"PlanarConfiguration",530:"YCbCrSubSampling",531:"YCbCrPositioning",282:"XResolution",283:"YResolution",296:"ResolutionUnit",273:"StripOffsets",278:"RowsPerStrip",279:"StripByteCounts",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",301:"TransferFunction",318:"WhitePoint",319:"PrimaryChromaticities",529:"YCbCrCoefficients",532:"ReferenceBlackWhite",306:"DateTime",270:"ImageDescription",271:"Make",272:"Model",305:"Software",315:"Artist",33432:"Copyright"},o={0:"GPSVersionID",1:"GPSLatitudeRef",2:"GPSLatitude",3:"GPSLongitudeRef",4:"GPSLongitude",5:"GPSAltitudeRef",6:"GPSAltitude",7:"GPSTimeStamp",8:"GPSSatellites",9:"GPSStatus",10:"GPSMeasureMode",11:"GPSDOP",12:"GPSSpeedRef",13:"GPSSpeed",14:"GPSTrackRef",15:"GPSTrack",16:"GPSImgDirectionRef",17:"GPSImgDirection",18:"GPSMapDatum",19:"GPSDestLatitudeRef",20:"GPSDestLatitude",21:"GPSDestLongitudeRef",22:"GPSDestLongitude",23:"GPSDestBearingRef",24:"GPSDestBearing",25:"GPSDestDistanceRef",26:"GPSDestDistance",27:"GPSProcessingMethod",28:"GPSAreaInformation",29:"GPSDateStamp",30:"GPSDifferential"},p={ExposureProgram:{0:"Not defined",1:"Manual",2:"Normal program",3:"Aperture priority",4:"Shutter priority",5:"Creative program",6:"Action program",7:"Portrait mode",8:"Landscape mode"},MeteringMode:{0:"Unknown",1:"Average",2:"CenterWeightedAverage",3:"Spot",4:"MultiSpot",5:"Pattern",6:"Partial",255:"Other"},LightSource:{0:"Unknown",1:"Daylight",2:"Fluorescent",3:"Tungsten (incandescent light)",4:"Flash",9:"Fine weather",10:"Cloudy weather",11:"Shade",12:"Daylight fluorescent (D 5700 - 7100K)",13:"Day white fluorescent (N 4600 - 5400K)",14:"Cool white fluorescent (W 3900 - 4500K)",15:"White fluorescent (WW 3200 - 3700K)",17:"Standard light A",18:"Standard light B",19:"Standard light C",20:"D55",21:"D65",22:"D75",23:"D50",24:"ISO studio tungsten",255:"Other"},Flash:{0:"Flash did not fire",1:"Flash fired",5:"Strobe return light not detected",7:"Strobe return light detected",9:"Flash fired, compulsory flash mode",13:"Flash fired, compulsory flash mode, return light not detected",15:"Flash fired, compulsory flash mode, return light detected",16:"Flash did not fire, compulsory flash mode",24:"Flash did not fire, auto mode",25:"Flash fired, auto mode",29:"Flash fired, auto mode, return light not detected",31:"Flash fired, auto mode, return light detected",32:"No flash function",65:"Flash fired, red-eye reduction mode",69:"Flash fired, red-eye reduction mode, return light not detected",71:"Flash fired, red-eye reduction mode, return light detected",73:"Flash fired, compulsory flash mode, red-eye reduction mode",77:"Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected",79:"Flash fired, compulsory flash mode, red-eye reduction mode, return light detected",89:"Flash fired, auto mode, red-eye reduction mode",93:"Flash fired, auto mode, return light not detected, red-eye reduction mode",95:"Flash fired, auto mode, return light detected, red-eye reduction mode"},SensingMethod:{1:"Not defined",2:"One-chip color area sensor",3:"Two-chip color area sensor",4:"Three-chip color area sensor",5:"Color sequential area sensor",7:"Trilinear sensor",8:"Color sequential linear sensor"},SceneCaptureType:{0:"Standard",1:"Landscape",2:"Portrait",3:"Night scene"},SceneType:{1:"Directly photographed"},CustomRendered:{0:"Normal process",1:"Custom process"},WhiteBalance:{0:"Auto white balance",1:"Manual white balance"},GainControl:{0:"None",1:"Low gain up",2:"High gain up",3:"Low gain down",4:"High gain down"},Contrast:{0:"Normal",1:"Soft",2:"Hard"},Saturation:{0:"Normal",1:"Low saturation",2:"High saturation"},Sharpness:{0:"Normal",1:"Soft",2:"Hard"},SubjectDistanceRange:{0:"Unknown",1:"Macro",2:"Close view",3:"Distant view"},FileSource:{3:"DSC"},Components:{0:"",1:"Y",2:"Cb",3:"Cr",4:"R",5:"G",6:"B"}};return{readFromBinaryFile:k,pretty:j,getTag:h,getAllTags:i,getData:g,Tags:m,TiffTags:n,GPSTags:o,StringValues:p}}();