zephyr/boards/arm/pinetime_devkit0
Gerard Marull-Paretas e81e92dbb9 boards: convert images to JPEG and reduce image size
The boards folder uses ~142.8 MB, being the largest in the repository.
This is due mostly to board images, which are in most cases not
optimized for web content. This patch tries to address this problem by
converting all pictures to JPEG (quality 75) and by adjusting its size
up to 750 px (the width of the documentation content). Images that
specified a fixed width in rst files are converted down to that value
instead.

With this patch, folder goes down to ~53.5 MB from 142.8 MB (-~63%).
Note that this patch introduces a new set of binary files to git
history, though (bad).

The process has been automated using this quickly crafted Python script:

```python
from pathlib import Path
import re
import subprocess

def process(doc, image, image_jpeg, size):
    subprocess.run(
        (
	     f"convert {image}"
	     "-background white -alpha remove -alpha off -quality 75"
	     f"-resize {size}\> {image_jpeg}"
	),
        shell=True,
        check=True,
        cwd=doc.parent,
    )
    if image != image_jpeg:
        (doc.parent / image).unlink()

for doc in Path(".").glob("boards/**/*.rst"):
    with open(doc) as f:
        content = ""
        image = None
        for line in f:
            m = re.match(r"^(\s*)\.\. (image|figure):: (.*)$", line)
            if m:
                if image:
                    process(doc, image, image_jpeg, size)

                image = Path(m.group(3))
                if image.suffix not in (".jpg", ".jpeg", ".png"):
                    content += line
                    image = None
                    continue

                image_jpeg = image.parent / (image.stem + ".jpg")
                size = 750
                content += (
                    f"{m.group(1)}.. {m.group(2)}:: {image_jpeg}\n"
                )
            elif image:
                m = re.match(r"\s*:height:\s*[0-9]+.*$", line)
                if m:
                    continue

                m = re.match(r"\s*:width:\s*([0-9]+).*$", line)
                if m:
                    size = min(int(m.group(1)), size)
                    continue

                content += line
                if line == "\n":
                    process(doc, image, image_jpeg, size)
                    image = None
            else:
                content += line

    with open(doc, "w") as f:
        f.write(content)
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-08-29 10:18:18 +02:00
..
doc boards: convert images to JPEG and reduce image size 2022-08-29 10:18:18 +02:00
dts/bindings/misc boards: arm: pinetime: Fix key definition 2021-12-14 12:32:32 +01:00
CMakeLists.txt boards: arm: pinetime: Fix minimal sample build 2022-04-04 09:38:10 -05:00
Kconfig.board boards: Adapt Pinetime board configuration 2020-11-11 13:28:11 +01:00
Kconfig.defconfig drivers: kscan: Remove unnecessary Kconfig settings 2022-08-09 23:37:46 -05:00
board.cmake boards: nrf: pyocd: Fix pyocd invocation strings 2022-03-25 12:36:17 -05:00
key_out.c boards: migrate includes to <zephyr/...> 2022-05-06 19:57:15 +02:00
pinetime_devkit0-pinctrl.dtsi boards: arm: pinetime_devkit0: migrate to pinctrl 2022-03-21 15:09:28 +01:00
pinetime_devkit0.dts kscan: Introduce zephyr,keyboard-scan chosen prop 2022-08-12 17:54:03 -05:00
pinetime_devkit0.yaml drivers: kscan: add support for cst816s touch panel driver 2022-03-01 14:24:27 -06:00
pinetime_devkit0_defconfig boards: remove non-minimal peripherals from defconfig 2022-08-05 12:55:51 +02:00
pre_dt_board.cmake boards: nrf52: Suppress DTC warnings about duplicate unit-address 2022-04-02 15:14:38 +02:00