Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
klaussa opened this issue May 23, 2017 · 6 comments
Open

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

klaussa opened this issue May 23, 2017 · 6 comments

Comments

@klaussa
Copy link

klaussa commented May 23, 2017

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
Copy link
Owner

hMatoba commented May 24, 2017

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
Copy link
Author

klaussa commented May 24, 2017

@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
Copy link
Owner

hMatoba commented May 24, 2017

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

@mdrx-io
Copy link

mdrx-io commented Mar 24, 2020

@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
Copy link

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

@krydos
Copy link

krydos commented Aug 19, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants