Skip to content

Conversation

@BimBoss
Copy link
Owner

@BimBoss BimBoss commented Feb 10, 2018

Problem:

Many libraries (for example bwip-js) encoding their images with decimal numbers and returning it to the buffer. So first byte of generated image looks like a decimal number, for example data[0] for PNG image, generated by bwip-js is 137 (0x89 in hex) and for JPEG - data[0] is 255 (0xff in hex). Your code checking image only if first byte is hexadecimal number, but it can be decimal too.
Because of that, valid images can't pass verification in the if...else statement and code throws an error 'Unknown image format.'.

Solving:

So my changes add the opportunity to verificate if image is encoded with a decimal number. I have tested my changes in real projects, and your library works perfect with decimal encoded images and inserts the picture into the pdf document exactly as hexadecimal encoded image. Thank you.

Many libraries (for example bwip-js) encoding their images with decimal numbers and returning it to the buffer. So first byte of generated image looks like a decimal number, for example data[0] for PNG image, generated by bwip-js is 137 (0x89 in hex) and for JPEG - data[0] is 255 (0xff in hex). Your code checking image only if first byte is hexadecimal number, but it can be decimal too.
Because of that, valid images can't pass verification in the if...else statement and code throws an error 'Unknown image format.'.
So my changes add the opportunity to check if image is encoded with decimal number and work with it. I have tested my changes in real projects, and your library works perfect with decimal encoded images. Thank you.
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

Successfully merging this pull request may close these issues.

2 participants