write_icc.py

Die Python-Datei des Beispiels „Das eingebettete ICC-Profil“. Das ICC-Profil, das die Bibliothek in eine PDF/A-Datei einbettet.

Python 36 Zeilen

Wofür dieses Beispiel da ist

Dieser Eintrag ist ein Download, keine Seite zum Ansehen. Eine zur Archivierung bestimmte Datei muss ein Farbprofil tragen, das das Gerät beschreibt, für das ihre Farben bestimmt sind, und die übliche Antwort ist, das eines anderen mitzuliefern: hundert Kilobyte oder mehr, mit einer angehängten Lizenz, in jedes Dokument kopiert, das Sie je erzeugen.

Was dieses Beispiel zeigt

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""Writes the ICC profile the library embeds in a PDF/A file.

The Python twin of the `write_icc` example in Rust: the same bytes, through the
binding rather than through the library directly.

The profile is built from the colorimetry sRGB is defined by rather than
shipped as a file, so what a document embeds can be looked at on its own —
whether it is a well-formed ICC profile, and whether it is really sRGB, is what
`scripts/check_icc_profile.py` uses this for.

Usage: python examples/write_icc.py [out.icc]
"""

from __future__ import annotations

import sys
from pathlib import Path

import hqf_pdf

ROOT = Path(__file__).resolve().parents[3]


def main() -> None:
    out = Path(sys.argv[1]) if len(sys.argv) > 1 else ROOT / "tmp" / "srgb.icc"

    profile = hqf_pdf.srgb_icc_profile()

    out.parent.mkdir(parents=True, exist_ok=True)
    out.write_bytes(profile)

    print(f"wrote {out}: {len(profile)} bytes")


if __name__ == "__main__":
    main()