-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmExif.min.js
2 lines (2 loc) · 6.68 KB
/
mExif.min.js
1
2
/* The MIT License (MIT) */
var mExif={_data:null,_offset:0,_bigEndian:!0,_constants:{MAX_SLICE_SIZE:131076},_tagLabel:{TIFF:{256:"ImageWidth",257:"ImageLength",258:"BitsPerSample",259:"Compression",262:"PhotometricInterpretation",270:"ImageDescription",271:"Make",272:"Model",273:"StripOffsets",274:"Orientation",277:"SamplesPerPixel",278:"RowsPerStrip",279:"StripByteCounts",282:"XResolution",283:"YResolution",284:"PlanarConfiguration",296:"ResolutionUnit",301:"TransferFunction",305:"Software",306:"DateTime",315:"Artist",318:"WhitePoint",319:"PrimaryChromaticities",513:"JPEGInterchangeFormat",514:"JPEGInterchangeFormatLength",529:"YCbCrCoefficients",530:"YCbCrSubSampling",531:"YCbCrPositioning",532:"ReferenceBlackWhite",33432:"Copyright",34665:"ExifIFDPointer",34853:"GPSIFDPointer"},Exif:{33434:"ExposureTime",33437:"FNumber",34850:"ExposureProgram",34852:"SpectralSensitivity",34855:"PhotographicSensitivity",34856:"OECF",34864:"SensitivityType",34865:"StandardOutputSensitivity",34866:"RecommendedExposureIndex",34867:"ISOSpeed",34868:"ISOSpeedLatitudeyyy",34869:"ISOSpeedLatitudezzz",36864:"ExifVersion",36867:"DateTimeOriginal",36868:"DateTimeDigitized",37121:"ComponentsConfiguration",37122:"CompressedBitsPerPixel",37377:"ShutterSpeedValue",37378:"ApertureValue",37379:"BrightnessValue",37380:"ExposureBiasValue",37381:"MaxApertureValue",37382:"SubjectDistance",37383:"MeteringMode",37384:"LightSource",37385:"Flash",37386:"FocalLength",37396:"SubjectArea",37500:"MakerNote",37510:"UserComment",37520:"SubSecTime",37521:"SubSecTimeOriginal",37522:"SubSecTimeDigitized",40960:"FlashpixVersion",40961:"ColorSpace",40962:"PixelXDimension",40963:"PixelYDimension",40964:"RelatedSoundFile",40965:"InteroperabilityIFDPointer",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:"DigitalZoomRatio",41989:"FocalLengthIn35mmFilm",41990:"SceneCaptureType",41991:"GainControl",41992:"Contrast",41993:"Saturation",41994:"Sharpness",41995:"DeviceSettingDescription",41996:"SubjectDistanceRange",42016:"ImageUniqueID",42032:"CameraOwnerName",42033:"BodySerialNumber",42034:"LensSpecification",42035:"LensMake",42036:"LensModel",42037:"LensSerialNumber",42240:"Gamma"},GPS:{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",31:"GPSHPositioningError"}},debugMode:!1,_log:function(e){this.debugMode&&console.log("[mExif] "+e)},_readByte:function(){return this._data.charCodeAt(this._offset++)},_readASCII:function(){return this._data.charAt(this._offset++)},_readShort:function(){var e=this._readByte(),t=this._readByte();return this._bigEndian?256*e+t:256*t+e},_readLong:function(){var e=this._readByte(),t=this._readByte(),i=this._readByte(),a=this._readByte();return this._bigEndian?16777216*e+65536*t+256*i+a:16777216*a+65536*i+256*t+e},_readRational:function(){var e=this._readLong(),t=this._readLong();return e+" / "+t},_readSLong:function(){var e=this._readLong();return e>2147483647?this._readLong()-4294967296:e},_readSRational:function(){var e=this._readSLong(),t=this._readSLong();return e+" / "+t},_readIFD:function(){var e=this._offset+12,t=this._readShort(),i=this._readShort(),a=this._readLong(),r=!1,n=[];switch(i){case 1:a>4&&(r=!0);break;case 2:a>3&&(r=!0);break;case 3:a>2&&(r=!0);break;case 4:a>1&&(r=!0);break;case 5:r=!0;break;case 7:a>4&&(r=!0);break;case 9:a>1&&(r=!0);break;case 10:r=!0;break;default:return this._log("unknown type: "+i),this._offset=e,null}r&&(this._offset=this._readLong());for(var o=0;a>o;o++)switch(i){case 1:n.push(this._readByte());break;case 2:n.push(this._readASCII());break;case 3:n.push(this._readShort());break;case 4:n.push(this._readLong());break;case 5:n.push(this._readRational());break;case 7:n.push(this._readASCII());break;case 9:n.push(this._readSLong());break;case 10:n.push(this._readSRational())}return 2===i&&n.pop(),(2===i||7===i)&&(n=n.join("")),this._offset=e,{tag:t,value:n}},_readIFDs:function(e){var t=this._readShort(),i={};this._log(t+" tags found");for(var a=0;t>a;a++){var r=this._readIFD();null!==r&&(e[r.tag]?i[e[r.tag]]=r.value:(this._log("couldn't find a label for "+r.tag),i[r.tag]=r.value))}return i},_getSlice:function(e){return e.slice?e.slice(0,this._constants.MAX_SLICE_SIZE):e.webkitSlice?e.webkitSlice(0,this._constants.MAX_SLICE_SIZE):e.mozSlice?e.mozSlice(0,this._constants.MAX_SLICE_SIZE):e},_checkSOI:function(e){var t=e.substring(0,2);return t!==String.fromCharCode(255,216)?(this._log("not a JPEG file"),!1):!0},_getAPP1:function(e){for(var t=2;t<this._constants.MAX_SLICE_SIZE-3;){var i=256*e.charCodeAt(t)+e.charCodeAt(t+1),a=256*e.charCodeAt(t+2)+e.charCodeAt(t+3);if(65504>i||i>65519)return this._log("couldn't find APPn header"),null;if(65505===i)return e.substring(t,t+2+a);this._log("skipping APP"+(i-65504)),t+=2+a}return this._log("couldn't find APP1 header"),null},_getTIFF:function(e){var t=e.substring(4,10),i=e.substring(10,14);if(t!==String.fromCharCode(69,120,105,102,0,0))return this._log("couldn't find Exif header"),null;if(i===String.fromCharCode(73,73,42,0))this._log("Endianness: little"),this._bigEndian=!1,this._offset=16777216*e.charCodeAt(17)+65536*e.charCodeAt(16)+256*e.charCodeAt(15)+e.charCodeAt(14);else{if(i!==String.fromCharCode(77,77,0,42))return this._log("couldn't find TIFF header"),null;this._log("Endianness: big"),this._bigEndian=!0,this._offset=16777216*e.charCodeAt(14)+65536*e.charCodeAt(15)+256*e.charCodeAt(16)+e.charCodeAt(17)}return e.substring(10)},scan:function(e,t){var i=this,a={},r={},n={},o=this._getSlice(e);fileReader=new FileReader,fileReader.onload=function(){if(!i._checkSOI(this.result))return void t(a);var e=i._getAPP1(this.result);return null===e?void t(a):(i._data=i._getTIFF(e),null===i._data?void t(a):(i._log("scanning TIFF tags"),a=i._readIFDs(i._tagLabel.TIFF),a.ExifIFDPointer&&(i._log("scanning Exif tags"),i._offset=a.ExifIFDPointer,r=i._readIFDs(i._tagLabel.Exif)),a.GPSIFDPointer&&(i._log("scanning GPS tags"),i._offset=a.GPSIFDPointer,n=i._readIFDs(i._tagLabel.GPS)),void t({TIFF:a,Exif:r,GPS:n})))},fileReader.readAsBinaryString(o)}};