Add style attribute to HTML image tags to limit the width of images
Go to file
2022-03-08 12:43:55 +01:00
.idea v1.0.1; update PKGBUILD (license); improve doc 2022-03-08 12:43:55 +01:00
.gitignore init 2021-09-15 17:27:01 +02:00
example.html init 2021-09-15 17:27:01 +02:00
image-width-limit.py v1.0.1; update PKGBUILD (license); improve doc 2022-03-08 12:43:55 +01:00
LICENSE add LICENSE 2022-03-02 12:46:10 +01:00
PKGBUILD v1.0.1; update PKGBUILD (license); improve doc 2022-03-08 12:43:55 +01:00
README.md v1.0.1; update PKGBUILD (license); improve doc 2022-03-08 12:43:55 +01:00

(HTML) Image width limit

From image-width-limit.py, function limit_image_width:

When converting HTML5 to other formats, e.g. PDF, it may happen that too wide images get cropped of.

If there are HTML5 image tags which do only contain the 'src' and 'alt' attribute, then this method adds the following style attribute to limit their width:

max-width:100%;height:auto;

Global Installation - Arch Linux

To install the script as de-p1st-image-width-limit run the following:

makepkg -fCcsri

Manual Installation

Install the python3 dependencies, e.g. with pip:

  • beautifulsoup4 (pacman -S python-beautifulsoup4)
  • html5lib (pacman -S python-html5lib)

And make the python script executable:

chmod +x ./image-width-limit.py

Example

Global installation:

de-p1st-image-width-limit example.html example_modified.html

Local installation:

python3 ./image-width-limit.py example.html example_modified.html