Skip to content

Make a page of a picture - #15

Merged
tannevaled merged 1 commit into
mainfrom
image-page
Aug 29, 2026
Merged

Make a page of a picture#15
tannevaled merged 1 commit into
mainfrom
image-page

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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 behind it.

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.

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 vet and -race clean, nine cross-compile targets.

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.
@tannevaled
tannevaled merged commit 23c9498 into main Aug 29, 2026
1 check passed
@tannevaled
tannevaled deleted the image-page branch August 29, 2026 19:09
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.

1 participant