hMatoba / piexifjs

Read and modify exif in client-side or server-side JavaScript.
MIT License
565 stars 117 forks source link

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

Open klaussa opened 7 years ago

klaussa commented 7 years ago

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

hMatoba commented 7 years ago

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]

klaussa commented 7 years ago

@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

hMatoba commented 7 years ago

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

mdrx-io commented 4 years ago

@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

SyedShehzadGillani commented 3 years ago

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

krydos commented 3 years ago

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.