Make a page of a picture - #15
Merged
Merged
Conversation
The other half of drawing a page. A scanner, a camera and a screenshot all produce a picture, and what people want of a PDF toolkit is to be handed one back with the picture in it. This package could take a document apart and put it together and could not begin one from an image. Picture takes every format go-gfx/gfx reads, which is more than a PDF can carry. A JPEG goes in as it stands, because a PDF carries JPEG and re-encoding one loses a little of it for nothing; everything else is decoded and written as samples, compressed. Every format is decoded either way, including the one carried undecoded, because the page has to be the size of the picture and only the picture says what that is. Transparency becomes a soft mask. Dropping the alpha channel instead puts the colour that was UNDER the transparency on the page, so a PNG with a clear background comes out with black or with whatever happened to be in those bytes. dpi says how many of the image's pixels go into an inch of paper. A photograph from a telephone at 72 is a page the size of a wall, and at 300 it is a photograph. A picture of no size is refused. Writing the test for that found the hole it now closes: GIF, BMP and JPEG all decode a zero-by-zero image WITHOUT complaining — such a file is not malformed, it is empty — and the check was on the path that decodes rather than on the one that only measures, so a JPEG of no size would have become a page of no size. Judged by poppler rather than by ourselves: it reads the files, lists the picture at the right size, carries the JPEG as jpeg, and renders the halves the right way round — the transparent half over white rather than over black. 100% statement coverage, go vet and -race clean, nine cross-compile targets.
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.
The other half of drawing a page. A scanner, a camera and a screenshot all produce a picture, and what people want of a PDF toolkit is to be handed one back with the picture in it. This package could take a document apart and put it together and could not begin one from an image.
Picturetakes every format go-gfx/gfx reads, which is more than a PDF can carry. A JPEG goes in as it stands, because a PDF carries JPEG and re-encoding one loses a little of it for nothing; everything else is decoded and written as samples, compressed. Every format is decoded either way, including the one carried undecoded, because the page has to be the size of the picture and only the picture says what that is.Transparency becomes a soft mask. Dropping the alpha channel instead puts the colour that was under the transparency on the page, so a PNG with a clear background comes out with black behind it.
dpisays how many of the image's pixels go into an inch of paper. A photograph from a telephone at 72 is a page the size of a wall, and at 300 it is a photograph.The hole the test found
A picture of no size is refused — and writing that test found the hole it now closes. GIF, BMP and JPEG all decode a zero-by-zero image without complaining: such a file is not malformed, it is empty. The check was on the path that decodes rather than on the one that only measures, so a JPEG of no size would have become a page of no size.
Judged by poppler rather than by ourselves
It reads the files, lists the picture at the right size, carries the JPEG as
jpeg, and renders the halves the right way round — the transparent half over white rather than over black.This is BentoPDF's Image to PDF, JPG to PDF, PNG to PDF, WebP to PDF, BMP to PDF and TIFF to PDF: six of the thirty-three in the family where we covered none.
100% statement coverage,
go vetand-raceclean, nine cross-compile targets.