A Picture Fitted into a Rectangle

A picture that comes from outside rarely has the proportions of the rectangle it has to go in. Stretched to fill the rectangle, it loses its proportions; kept at its own size, it leaves empty space around it or runs past the edge. That choice comes up again with every catalogue and every report you create.

So the decision is made once and named: fit the whole picture inside, fill the rectangle and let the edges be cut, stretch it and accept the distortion, leave it at the size it came, or shrink it only when it is too big. The same picture is shown here under sixteen such rules in a rectangle of one size — stood against an edge or at any of nine points, given a margin, turned a quarter, a half or by an angle, mirrored either way — and nothing on the page was measured by hand. Only the ones that fill their rectangle or come out larger than it overflow, and they are cut at the edge, on purpose.

What This Example Shows

  • Fit the whole picture inside, fill the rectangle and cut what overflows, stretch it to the edges, keep its own size, or shrink it only if it is too big.
  • Nine places to stand it, all shown at once; a margin inside the rectangle, turns of a quarter, a half and an angle, and a mirror each way.
  • The same picture in the same rectangle sixteen times, so the sixteen ways of fitting it can be compared.

The Source Code, Complete

Nothing is left out and nothing is simplified: this is the program exactly as it runs, for the developer who uses this library. The third is the description itself: a plain list of what the page has to say, which is what the service is sent.

Read the Rust source Read the Python source Read the JSON source

The Document Itself

Open the document in English Open the document in French Open the document in German Open the document in Spanish Open the document in Italian Open the document in Portuguese

A Picture Fitted into a Rectangle, first page

In the API Reference

The Same Document in Other Languages

This document weighs 19.6 kB

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.

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