Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.