piexifjs icon indicating copy to clipboard operation
piexifjs copied to clipboard

can't figure out how to add info to BYTE type fields

Open klaussa opened this issue 7 years ago • 6 comments

Hi,

I have been trying to figure out the way to convert a string for XPSubject into the required format. Can anyone please provide more guidance / examples on how the conversion between BYTE to javascrpt Int works ? ( i am considering to put text into subject )

thank you

klaussa avatar May 23 '17 22:05 klaussa

Which value do you want to add? Example:

var s = "foo";
var bytes = [];
for (var i=0; i<s.length; i++) {
    bytes.push(s.charCodeAt(i));
}

bytes -> [102, 111, 111]

hMatoba avatar May 24 '17 02:05 hMatoba

@hMatoba
I want to add a piece of text to those fields. // XPTitle: // XPComment: // XPAuthor: // XPKeywords: // XPSubject

The example you provided doesn't output foo but outputs a chinese character :(

I use this to check: http://metapicz.com/#landing ( + also I do windows -> properties -> details tab to check ).

Any advice ?

screen shot 2017-05-24 at 10 12 39

The Code looks like:

screen shot 2017-05-24 at 10 17 15

klaussa avatar May 24 '17 09:05 klaussa

It need to encode and decode as UCS2. Read the specification. http://www.exiv2.org/tags.html

hMatoba avatar May 24 '17 11:05 hMatoba

@klaussa finding the answer not straightforward, but this was my solution (using Node.js v12 and the new spread syntax):

exif[piexifjs.ImageIFD.XPTitle]: [...Buffer.from('Your XPTitle', 'ucs2')]

For more information, see: https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings https://nodejs.org/api/buffer.html#buffer_buffers_and_typedarrays Other background info: https://www.npmjs.com/package/punycode https://mathiasbynens.be/notes/javascript-encoding

mdrx-io avatar Mar 24 '20 22:03 mdrx-io

its saying uncaught pack error, when i used [...Buffer.from('Your XPTitle', 'ucs2')] using vue 3 js

SyedShehzadGillani avatar Jul 21 '21 08:07 SyedShehzadGillani

In my case this issue happened due to big number in exifObj['GPS'][piexif.GPSIFD.GPSTimeStamp]. But it definitely depends. It can be related to any EXIF field. Not only GPS related.

krydos avatar Aug 19 '21 18:08 krydos