How to use getExifSeg method in wpt

Best JavaScript code snippet using wpt

piexif.js

Source:piexif.js Github

copy

Full Screen

...428 var segments,429 app1;430 if (data.slice(0, 2) == "\xff\xd8") { // JPEG431 segments = splitIntoSegments(data);432 app1 = getExifSeg(segments);433 if (app1) {434 this.tiftag = app1.slice(10);435 } else {436 this.tiftag = null;437 }438 } else if (["\x49\x49", "\x4d\x4d"].indexOf(data.slice(0, 2)) > -1) { // TIFF439 this.tiftag = data;440 } else if (data.slice(0, 4) == "Exif") { // Exif441 this.tiftag = data.slice(6);442 } else {443 throw ("Given file is neither JPEG nor TIFF.");444 }445 }446 ExifReader.prototype = {447 get_ifd: function (pointer, ifd_name) {448 var ifd_dict = {};449 var tag_count = unpack(this.endian_mark + "H",450 this.tiftag.slice(pointer, pointer + 2))[0];451 var offset = pointer + 2;452 var t;453 if (["0th", "1st"].indexOf(ifd_name) > -1) {454 t = "Image";455 } else {456 t = ifd_name;457 }458 for (var x = 0; x < tag_count; x++) {459 pointer = offset + 12 * x;460 var tag = unpack(this.endian_mark + "H",461 this.tiftag.slice(pointer, pointer + 2))[0];462 var value_type = unpack(this.endian_mark + "H",463 this.tiftag.slice(pointer + 2, pointer + 4))[0];464 var value_num = unpack(this.endian_mark + "L",465 this.tiftag.slice(pointer + 4, pointer + 8))[0];466 var value = this.tiftag.slice(pointer + 8, pointer + 12);467 var v_set = [value_type, value_num, value];468 if (tag in TAGS[t]) {469 ifd_dict[tag] = this.convert_value(v_set);470 }471 }472 if (ifd_name == "0th") {473 pointer = offset + 12 * tag_count;474 ifd_dict["first_ifd_pointer"] = this.tiftag.slice(pointer, pointer + 4);475 }476 return ifd_dict;477 },478 convert_value: function (val) {479 var data = null;480 var t = val[0];481 var length = val[1];482 var value = val[2];483 var pointer;484 if (t == 1) { // BYTE485 if (length > 4) {486 pointer = unpack(this.endian_mark + "L", value)[0];487 data = unpack(this.endian_mark + nStr("B", length),488 this.tiftag.slice(pointer, pointer + length));489 } else {490 data = unpack(this.endian_mark + nStr("B", length), value.slice(0, length));491 }492 } else if (t == 2) { // ASCII493 if (length > 4) {494 pointer = unpack(this.endian_mark + "L", value)[0];495 data = this.tiftag.slice(pointer, pointer + length - 1);496 } else {497 data = value.slice(0, length - 1);498 }499 } else if (t == 3) { // SHORT500 if (length > 2) {501 pointer = unpack(this.endian_mark + "L", value)[0];502 data = unpack(this.endian_mark + nStr("H", length),503 this.tiftag.slice(pointer, pointer + length * 2));504 } else {505 data = unpack(this.endian_mark + nStr("H", length),506 value.slice(0, length * 2));507 }508 } else if (t == 4) { // LONG509 if (length > 1) {510 pointer = unpack(this.endian_mark + "L", value)[0];511 data = unpack(this.endian_mark + nStr("L", length),512 this.tiftag.slice(pointer, pointer + length * 4));513 } else {514 data = unpack(this.endian_mark + nStr("L", length),515 value);516 }517 } else if (t == 5) { // RATIONAL518 pointer = unpack(this.endian_mark + "L", value)[0];519 if (length > 1) {520 data = [];521 for (var x = 0; x < length; x++) {522 data.push([unpack(this.endian_mark + "L",523 this.tiftag.slice(pointer + x * 8, pointer + 4 + x * 8))[0],524 unpack(this.endian_mark + "L",525 this.tiftag.slice(pointer + 4 + x * 8, pointer + 8 + x * 8))[0]526 ]);527 }528 } else {529 data = [unpack(this.endian_mark + "L",530 this.tiftag.slice(pointer, pointer + 4))[0],531 unpack(this.endian_mark + "L",532 this.tiftag.slice(pointer + 4, pointer + 8))[0]533 ];534 }535 } else if (t == 7) { // UNDEFINED BYTES536 if (length > 4) {537 pointer = unpack(this.endian_mark + "L", value)[0];538 data = this.tiftag.slice(pointer, pointer + length);539 } else {540 data = value.slice(0, length);541 }542 } else if (t == 10) { // SRATIONAL543 pointer = unpack(this.endian_mark + "L", value)[0];544 if (length > 1) {545 data = [];546 for (var x = 0; x < length; x++) {547 data.push([unpack(this.endian_mark + "l",548 this.tiftag.slice(pointer + x * 8, pointer + 4 + x * 8))[0],549 unpack(this.endian_mark + "l",550 this.tiftag.slice(pointer + 4 + x * 8, pointer + 8 + x * 8))[0]551 ]);552 }553 } else {554 data = [unpack(this.endian_mark + "l",555 this.tiftag.slice(pointer, pointer + 4))[0],556 unpack(this.endian_mark + "l",557 this.tiftag.slice(pointer + 4, pointer + 8))[0]558 ];559 }560 } else {561 throw ("Exif might be wrong. Got incorrect value " +562 "type to decode. type:" + t);563 }564 if ((data instanceof Array) && (data.length == 1)) {565 return data[0];566 } else {567 return data;568 }569 },570 };571 if (typeof window !== "undefined" && typeof window.btoa === "function") {572 var btoa = window.btoa;573 }574 if (typeof btoa === "undefined") {575 var btoa = function (input) { var output = "";576 var chr1, chr2, chr3, enc1, enc2, enc3, enc4;577 var i = 0;578 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";579 while (i < input.length) {580 chr1 = input.charCodeAt(i++);581 chr2 = input.charCodeAt(i++);582 chr3 = input.charCodeAt(i++);583 enc1 = chr1 >> 2;584 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);585 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);586 enc4 = chr3 & 63;587 if (isNaN(chr2)) {588 enc3 = enc4 = 64;589 } else if (isNaN(chr3)) {590 enc4 = 64;591 }592 output = output +593 keyStr.charAt(enc1) + keyStr.charAt(enc2) +594 keyStr.charAt(enc3) + keyStr.charAt(enc4);595 }596 return output;597 };598 }599 600 601 if (typeof window !== "undefined" && typeof window.atob === "function") {602 var atob = window.atob;603 }604 if (typeof atob === "undefined") {605 var atob = function (input) {606 var output = "";607 var chr1, chr2, chr3;608 var enc1, enc2, enc3, enc4;609 var i = 0;610 var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";611 input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");612 while (i < input.length) {613 enc1 = keyStr.indexOf(input.charAt(i++));614 enc2 = keyStr.indexOf(input.charAt(i++));615 enc3 = keyStr.indexOf(input.charAt(i++));616 enc4 = keyStr.indexOf(input.charAt(i++));617 chr1 = (enc1 << 2) | (enc2 >> 4);618 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);619 chr3 = ((enc3 & 3) << 6) | enc4;620 output = output + String.fromCharCode(chr1);621 if (enc3 != 64) {622 output = output + String.fromCharCode(chr2);623 }624 if (enc4 != 64) {625 output = output + String.fromCharCode(chr3);626 }627 }628 return output;629 };630 }631 function getImageSize(imageArray) {632 var segments = slice2Segments(imageArray);633 var seg,634 width,635 height,636 SOF = [192, 193, 194, 195, 197, 198, 199, 201, 202, 203, 205, 206, 207];637 for (var x = 0; x < segments.length; x++) {638 seg = segments[x];639 if (SOF.indexOf(seg[1]) >= 0) {640 height = seg[5] * 256 + seg[6];641 width = seg[7] * 256 + seg[8];642 break;643 }644 }645 return [width, height];646 }647 function pack(mark, array) {648 if (!(array instanceof Array)) {649 throw ("'pack' error. Got invalid type argument.");650 }651 if ((mark.length - 1) != array.length) {652 throw ("'pack' error. " + (mark.length - 1) + " marks, " + array.length + " elements.");653 }654 var littleEndian;655 if (mark[0] == "<") {656 littleEndian = true;657 } else if (mark[0] == ">") {658 littleEndian = false;659 } else {660 throw ("");661 }662 var packed = "";663 var p = 1;664 var val = null;665 var c = null;666 var valStr = null;667 while (c = mark[p]) {668 if (c.toLowerCase() == "b") {669 val = array[p - 1];670 if ((c == "b") && (val < 0)) {671 val += 0x100;672 }673 if ((val > 0xff) || (val < 0)) {674 throw ("'pack' error.");675 } else {676 valStr = String.fromCharCode(val);677 }678 } else if (c == "H") {679 val = array[p - 1];680 if ((val > 0xffff) || (val < 0)) {681 throw ("'pack' error.");682 } else {683 valStr = String.fromCharCode(Math.floor((val % 0x10000) / 0x100)) +684 String.fromCharCode(val % 0x100);685 if (littleEndian) {686 valStr = valStr.split("").reverse().join("");687 }688 }689 } else if (c.toLowerCase() == "l") {690 val = array[p - 1];691 if ((c == "l") && (val < 0)) {692 val += 0x100000000;693 }694 if ((val > 0xffffffff) || (val < 0)) {695 throw ("'pack' error.");696 } else {697 valStr = String.fromCharCode(Math.floor(val / 0x1000000)) +698 String.fromCharCode(Math.floor((val % 0x1000000) / 0x10000)) +699 String.fromCharCode(Math.floor((val % 0x10000) / 0x100)) +700 String.fromCharCode(val % 0x100);701 if (littleEndian) {702 valStr = valStr.split("").reverse().join("");703 }704 }705 } else {706 throw ("'pack' error.");707 }708 packed += valStr;709 p += 1;710 }711 return packed;712 }713 function unpack(mark, str) {714 if (typeof (str) != "string") {715 throw ("'unpack' error. Got invalid type argument.");716 }717 var l = 0;718 for (var markPointer = 1; markPointer < mark.length; markPointer++) {719 if (mark[markPointer].toLowerCase() == "b") {720 l += 1;721 } else if (mark[markPointer].toLowerCase() == "h") {722 l += 2;723 } else if (mark[markPointer].toLowerCase() == "l") {724 l += 4;725 } else {726 throw ("'unpack' error. Got invalid mark.");727 }728 }729 if (l != str.length) {730 throw ("'unpack' error. Mismatch between symbol and string length. " + l + ":" + str.length);731 }732 var littleEndian;733 if (mark[0] == "<") {734 littleEndian = true;735 } else if (mark[0] == ">") {736 littleEndian = false;737 } else {738 throw ("'unpack' error.");739 }740 var unpacked = [];741 var strPointer = 0;742 var p = 1;743 var val = null;744 var c = null;745 var length = null;746 var sliced = "";747 while (c = mark[p]) {748 if (c.toLowerCase() == "b") {749 length = 1;750 sliced = str.slice(strPointer, strPointer + length);751 val = sliced.charCodeAt(0);752 if ((c == "b") && (val >= 0x80)) {753 val -= 0x100;754 }755 } else if (c == "H") {756 length = 2;757 sliced = str.slice(strPointer, strPointer + length);758 if (littleEndian) {759 sliced = sliced.split("").reverse().join("");760 }761 val = sliced.charCodeAt(0) * 0x100 +762 sliced.charCodeAt(1);763 } else if (c.toLowerCase() == "l") {764 length = 4;765 sliced = str.slice(strPointer, strPointer + length);766 if (littleEndian) {767 sliced = sliced.split("").reverse().join("");768 }769 val = sliced.charCodeAt(0) * 0x1000000 +770 sliced.charCodeAt(1) * 0x10000 +771 sliced.charCodeAt(2) * 0x100 +772 sliced.charCodeAt(3);773 if ((c == "l") && (val >= 0x80000000)) {774 val -= 0x100000000;775 }776 } else {777 throw ("'unpack' error. " + c);778 }779 unpacked.push(val);780 strPointer += length;781 p += 1;782 }783 return unpacked;784 }785 function nStr(ch, num) {786 var str = "";787 for (var i = 0; i < num; i++) {788 str += ch;789 }790 return str;791 }792 function splitIntoSegments(data) {793 if (data.slice(0, 2) != "\xff\xd8") {794 throw ("Given data isn't JPEG.");795 }796 var head = 2;797 var segments = ["\xff\xd8"];798 while (true) {799 if (data.slice(head, head + 2) == "\xff\xda") {800 segments.push(data.slice(head));801 break;802 } else {803 var length = unpack(">H", data.slice(head + 2, head + 4))[0];804 var endPoint = head + length + 2;805 segments.push(data.slice(head, endPoint));806 head = endPoint;807 }808 if (head >= data.length) {809 throw ("Wrong JPEG data.");810 }811 }812 return segments;813 }814 function getExifSeg(segments) {815 var seg;816 for (var i = 0; i < segments.length; i++) {817 seg = segments[i];818 if (seg.slice(0, 2) == "\xff\xe1" &&819 seg.slice(4, 10) == "Exif\x00\x00") {820 return seg;821 }822 }823 return null;824 }825 function mergeSegments(segments, exif) {826 827 if (segments[1].slice(0, 2) == "\xff\xe0" &&828 (segments[2].slice(0, 2) == "\xff\xe1" &&...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var path = require('path');4var file = path.join(__dirname, 'test.jpg');5var exif = wptools.getExifSeg(file);6fs.writeFileSync("test.json", JSON.stringify(exif, null, 2));7{8 "scripts": {9 },10 "dependencies": {11 }12}13{14 "dependencies": {15 "wptools": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var options = {4};5var wp = new wptools.page('File:Koala.jpg', options);6wp.getExifSeg(function(err, result) {7 if (err) {8 console.log(err);9 return;10 }11 fs.writeFile('exif.json', JSON.stringify(result, null, 2), function(err) {12 if (err) {13 console.log(err);14 } else {15 console.log('exif.json saved.');16 }17 });18});19{

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wp-tools');2wptools.getExifSeg('./test.jpg', function(err, exif) {3 if (err) {4 console.log(err);5 }6 console.log(exif);7});8{ '0th': 9 { ImageWidth: 1024,

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = wptools.page('Albert Einstein');3wp.getExifSeg(function(err, exif) {4 if (err) {5 console.log('Error: ' + err);6 } else {7 console.log(exif);8 }9});10var wptools = require('wptools');11var wp = wptools.page('Albert Einstein');12wp.getExifSeg(function(err, exif) {13 if (err) {14 console.log('Error: ' + err);15 } else {16 console.log(exif);17 }18});19var wptools = require('wptools');20var wp = wptools.page('Albert Einstein');21wp.getExifSeg(function(err, exif) {22 if (err) {23 console.log('Error: ' + err);24 } else {25 console.log(exif);26 }27});28var wptools = require('wptools');29var wp = wptools.page('Albert Einstein');30wp.getExifSeg(function(err, exif) {31 if (err) {32 console.log('Error: ' + err);33 } else {34 console.log(exif);35 }36});37var wptools = require('wptools');38var wp = wptools.page('Albert Einstein');39wp.getExifSeg(function(err, exif) {40 if (err) {41 console.log('Error: ' + err);42 } else {43 console.log(exif);44 }45});46var wptools = require('wptools');47var wp = wptools.page('Albert Einstein');48wp.getExifSeg(function(err, exif) {49 if (err) {50 console.log('Error: ' + err);51 } else {52 console.log(exif);53 }54});55var wptools = require('wptools');56var wp = wptools.page('Albert Einstein');57wp.getExifSeg(function(err, exif) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var exif = wpt.getExifSeg('test.jpg');3console.log(exif);4var wpt = require('wpt');5var exif = wpt.getExifSeg('test.jpg');6console.log(exif);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2 if(err){3 console.log(err);4 }else{5 console.log(exif);6 }7});8var wptools = require('wptools');9 if(err){10 console.log(err);11 }else{12 console.log(exif);13 }14});15var wptools = require('wptools');16 if(err){17 console.log(err);18 }else{19 console.log(exif);20 }21});22var wptools = require('wptools');23 if(err){24 console.log(err);25 }else{26 console.log(exif);27 }28});29var wptools = require('wptools');30 if(err){31 console.log(err);32 }else{33 console.log(exif);34 }35});36var wptools = require('wptools');

Full Screen

Using AI Code Generation

copy

Full Screen

1var file = process.argv[2];2var wptools = require('./wptools.js');3var exif = wptools.getExifSeg(file);4console.log(exif);5console.log(wptools.exifToExifTool(exif));6console.log(wptools.exifToExifTool(exif, true));7console.log(wptools.exifToExifTool(exif, false, true));8console.log(wptools.exifToExifTool(exif, true, false));9console.log(wptools.exifToExifTool(exif, true, true));10console.log(wptools.exifToExifTool(exif, false, false));11console.log(wptools.exifToExifTool(exif, false, true));12console.log(wptools.exifToExifTool(exif, true, false));13console.log(wptools.exifToExifTool(exif, true, true));14console.log(wptools.exifToExifTool(exif, false, false));15console.log(wptools.exifToExifTool(exif

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful