Every picture a scanner put in one file

A scanner does not give you one file per sheet. It gives you one file with the whole batch inside, and the same is true of a fax machine: every page of the call is in there, one after another. Software that only looks at the first one quietly loses the rest, and nobody notices until the day somebody needs page four.

So the file is asked how many pictures it holds, and each of them is taken in turn and given a page cut to its own size. One of the two files on this page holds three sheets; the other holds a single photograph, and that one is copied across without being taken apart and put back together — a photograph is something reading software already knows how to show, so nothing is gained by touching it and quality is lost.

What this example shows

  • Every picture in the file, not just the first one.
  • Each one on a page cut to its own size.
  • A photograph inside the file is copied across untouched, so it comes out as sharp as it went in.

The source code, complete

Nothing is left out and nothing is simplified: this is the program exactly as it runs, for whoever writes your software.

Read the Rust source Read the Python source

The document itself

Open the document

Examples near this one

Images on a page

A photograph that goes in exactly as it came out of the camera, and one with transparent parts that keeps them, each on a page cut to its own size.

A gallery of picture formats

The four picture formats read — JPEG, PNG, BMP and TIFF — shown across every picture shipped with the library, each captioned with what its own file declares.

A picture fitted into a rectangle

One picture fitted into a rectangle of one size eight ways: three ways of sizing it, the same one stood in the top left corner with a 12-point inset, a quarter turn left, a quarter turn right, a turn of 20 degrees, and a left-to-right mirror — every panel drawing the picture at the place and the size the library worked out.

Two orders, one frame, one bottom edge

An order of four lines and one of seven, in frames of the same height, both ending on the same bottom edge. Underneath, two notes of unequal length whose lines are moved apart until each reaches the foot of its frame.

Code 128 and retail barcodes

Stripes for the two jobs that want them: Code 128 for any text at all, and the three a till reads — EAN-13, UPC-A, EAN-8 — each with its last digit worked out rather than typed.

QR codes

The code an invoice, a boarding pass or a label ends up wanting, drawn into the document rather than fetched as a picture and pasted in.

Every example, by subject