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

- added possibility to write comment tags #87

Merged
merged 5 commits into from Apr 7, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/encoder.js
Expand Up @@ -535,6 +535,19 @@ function JPEGEncoder(quality) {
writeByte(std_ac_chrominance_values[p]);
}
}

function writeCOM(comments)
{
if (typeof comments === "undefined") return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof comments === "undefined") return;
if (typeof comments !== 'string') return;

perhaps? but ya know, inside the loop with an array check here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will not work, I am afraid. The type is 'object' as it is an array.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, misunderstood your comment. I will change that tomorrow.

comments.forEach(e => {
writeWord(0xFFFE); // marker
var l = e.length;
writeWord(l + 2); // length itself as well
var i;
for (i = 0; i < l; i++)
writeByte(e.charCodeAt(i));
});
}

function writeSOS()
{
Expand Down Expand Up @@ -625,6 +638,7 @@ function JPEGEncoder(quality) {
// Add JPEG headers
writeWord(0xFFD8); // SOI
writeAPP0();
writeCOM(image.comments);
writeAPP1(image.exifBuffer);
writeDQT();
writeSOF0(image.width,image.height);
Expand Down