{"id":13815141,"url":"https://github.com/jarrekk/imgkit","last_synced_at":"2025-05-15T05:06:12.646Z","repository":{"id":37550153,"uuid":"80392844","full_name":"jarrekk/imgkit","owner":"jarrekk","description":"🌁 Wkhtmltoimage python wrapper to convert HTML to image","archived":false,"fork":false,"pushed_at":"2023-05-29T06:09:46.000Z","size":203,"stargazers_count":822,"open_issues_count":29,"forks_count":73,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-14T14:39:24.700Z","etag":null,"topics":["imgkit","wkhtmltoimage","wkhtmltopdf","wrapper","xvfb"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jarrekk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-01-30T04:12:59.000Z","updated_at":"2025-05-02T07:39:33.000Z","dependencies_parsed_at":"2024-01-15T13:35:44.078Z","dependency_job_id":null,"html_url":"https://github.com/jarrekk/imgkit","commit_stats":{"total_commits":130,"total_committers":12,"mean_commits":"10.833333333333334","dds":"0.34615384615384615","last_synced_commit":"3ee9977004a7ad24aaa71890f4591ce646d0b95e"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarrekk%2Fimgkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarrekk%2Fimgkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarrekk%2Fimgkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarrekk%2Fimgkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jarrekk","download_url":"https://codeload.github.com/jarrekk/imgkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254276447,"owners_count":22043867,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["imgkit","wkhtmltoimage","wkhtmltopdf","wrapper","xvfb"],"created_at":"2024-08-04T04:03:01.160Z","updated_at":"2025-05-15T05:06:10.202Z","avatar_url":"https://github.com/jarrekk.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# IMGKit: Python library of HTML to IMG wrapper\n\n[![Unit Test](https://github.com/jarrekk/imgkit/actions/workflows/unit_test.yml/badge.svg?branch=master)](https://github.com/jarrekk/imgkit/actions/workflows/unit_test.yml)\n[![codecov](https://codecov.io/gh/jarrekk/imgkit/branch/master/graph/badge.svg?token=pNl4TtuAzz)](https://codecov.io/gh/jarrekk/imgkit)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/581cfb2ff94b46aa930f11824703ea88)](https://www.codacy.com/gh/jarrekk/imgkit/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=jarrekk/imgkit\u0026amp;utm_campaign=Badge_Grade)\n[![Release](https://github.com/jarrekk/imgkit/actions/workflows/release.yml/badge.svg)](https://github.com/jarrekk/imgkit/actions/workflows/release.yml)\n[![PyPI version](https://badge.fury.io/py/imgkit.svg)](https://badge.fury.io/py/imgkit)\n\n```text\n  _____   __  __    _____   _  __  _   _\n |_   _| |  \\/  |  / ____| | |/ / (_) | |\n   | |   | \\  / | | |  __  | ' /   _  | |_\n   | |   | |\\/| | | | |_ | |  \u003c   | | | __|\n  _| |_  | |  | | | |__| | | . \\  | | | |_\n |_____| |_|  |_|  \\_____| |_|\\_\\ |_|  \\__|\n\n```\n\nPython 2 and 3 wrapper for wkhtmltoimage utility to convert HTML to IMG using Webkit.\n\n## Installation\n\n1.  Install imgkit:\n\n    ```python\n    pip install imgkit\n    ```\n\n1.  Install wkhtmltopdf:\n\n    - Debian/Ubuntu:\n\n      ```bash\n      sudo apt-get install wkhtmltopdf\n      ```\n\n      **Warning!** Version in debian/ubuntu repos have reduced functionality (because it compiled without the wkhtmltopdf QT patches), such as adding outlines, headers, footers, TOC etc. To use this options you should install static binary from [wkhtmltopdf](http://wkhtmltopdf.org/) site or you can use this [script](https://github.com/jarrekk/imgkit/blob/master/travis/init.sh).\n\n    - MacOSX:\n\n      ```bash\n      brew install --cask wkhtmltopdf\n      ```\n\n    - Windows and other options:\n\n      Check [wkhtmltopdf homepage](http://wkhtmltopdf.org/) for binary installers or [wiki page](https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF).\n\n## Usage\n\nSimple example:\n\n```python\nimport imgkit\n\nimgkit.from_url('http://google.com', 'out.jpg')\nimgkit.from_file('test.html', 'out.jpg')\nimgkit.from_string('Hello!', 'out.jpg')\n```\n\nAlso you can pass an opened file:\n\n```python\nwith open('file.html') as f:\n    imgkit.from_file(f, 'out.jpg')\n```\n\nIf you wish to further process generated IMG, you can read it to a variable:\n\n```python\n# Use False instead of output path to save pdf to a variable\nimg = imgkit.from_url('http://google.com', False)\n```\n\nYou can find all wkhtmltoimage options by type `wkhtmltoimage` command or visit this [Manual](https://wkhtmltopdf.org/usage/wkhtmltopdf.txt). You can drop '--' in option name. If option without value, use _None, False_ or _''_ for dict value:. For repeatable options (incl. allow, cookie, custom-header, post, postfile, run-script, replace) you may use a list or a tuple. With option that need multiple values (e.g. --custom-header Authorization secret) we may use a 2-tuple (see example below).\n\n```python\noptions = {\n    'format': 'png',\n    'crop-h': '3',\n    'crop-w': '3',\n    'crop-x': '3',\n    'crop-y': '3',\n    'encoding': \"UTF-8\",\n    'custom-header' : [\n        ('Accept-Encoding', 'gzip')\n    ],\n    'cookie': [\n        ('cookie-name1', 'cookie-value1'),\n        ('cookie-name2', 'cookie-value2'),\n    ],\n    'no-outline': None\n}\n\nimgkit.from_url('http://google.com', 'out.png', options=options)\n```\n\nAt some headless servers, perhaps you need to install **xvfb**:\n\n```bash\n# at ubuntu server, etc.\nsudo apt-get install xvfb\n# at centos server, etc.\nyum install xorg-x11-server-Xvfb\n```\n\nThen use **IMGKit** with option **xvfb**: `{\"xvfb\": \"\"}`.\n\nBy default, IMGKit will show all `wkhtmltoimage` output. If you don't want it, you need to pass `quiet` option:\n\n```python\noptions = {\n    'quiet': ''\n    }\n\nimgkit.from_url('google.com', 'out.jpg', options=options)\n```\n\nDue to wkhtmltoimage command syntax, **TOC** and **Cover** options must be specified separately. If you need cover before TOC, use `cover_first` option:\n\n```python\ntoc = {\n    'xsl-style-sheet': 'toc.xsl'\n}\n\ncover = 'cover.html'\n\nimgkit.from_file('file.html', options=options, toc=toc, cover=cover)\nimgkit.from_file('file.html', options=options, toc=toc, cover=cover, cover_first=True)\n```\n\nYou can specify external CSS files when converting files or strings using _css_ option.\n\n```python\n# Single CSS file\ncss = 'example.css'\nimgkit.from_file('file.html', options=options, css=css)\n\n# Multiple CSS files\ncss = ['example.css', 'example2.css']\nimgkit.from_file('file.html', options=options, css=css)\n```\n\nYou can also pass any options through meta tags in your HTML:\n\n```python\nbody = \"\"\"\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta name=\"imgkit-format\" content=\"png\"/\u003e\n    \u003cmeta name=\"imgkit-orientation\" content=\"Landscape\"/\u003e\n  \u003c/head\u003e\n  Hello World!\n\u003c/html\u003e\n\"\"\"\n\nimgkit.from_string(body, 'out.png')\n```\n\n## Configuration\n\nEach API call takes an optional config paramater. This should be an instance of `imgkit.config()` API call. It takes the config options as initial paramaters. The available options are:\n\n- `wkhtmltoimage` - the location of the `wkhtmltoimage` binary. By default `imgkit` will attempt to locate this using which` (on UNIX type systems) or where` (on Windows).\n- `xvfb` - the location of the `xvfb-run` binary. By default `imgkit` will attempt to locate this using which` (on UNIX type systems) or where` (on Windows).\n- `meta_tag_prefix` - the prefix for `imgkit` specific meta tags - by default this is `imgkit-`\n\nExample - for when `wkhtmltopdf` or `xvfb` is not in `$PATH`:\n\n```python\nconfig = imgkit.config(wkhtmltoimage='/opt/bin/wkhtmltoimage', xvfb='/opt/bin/xvfb-run')\nimgkit.from_string(html_string, output_file, config=config)\n```\n\n## Troubleshooting\n\n- `IOError: 'No wkhtmltopdf executable found'`:\n\n  Make sure that you have wkhtmltoimage in your `$PATH` or set via custom configuration (see preceding section). _where wkhtmltoimage_ in Windows or _which wkhtmltoimage_ on Linux should return actual path to binary.\n\n- `IOError: 'No xvfb executable found'`:\n\n  Make sure that you have xvfb-run in your `$PATH` or set via custom configuration (see preceding section). _where xvfb_ in Windows or _which xvfb-run_ or _which Xvfb_ on Linux should return actual path to binary.\n\n- `IOError: 'Command Failed'`:\n\n  This error means that IMGKit was unable to process an input. You can try to directly run a command from error message and see what error caused failure (on some wkhtmltoimage versions this can be cause by segmentation faults)\n\n## Credit\n\n[python PDFKit](https://github.com/JazzCore/python-pdfkit)\n\n## IMGKit author\n\n- **jarrekk** \u003chttps://github.com/jarrekk\u003e\n\n### Contributors\n\n- **v-hunt** \u003chttps://github.com/v-hunt\u003e\n- **archydeberker** \u003chttps://github.com/archydeberker\u003e\n- **arayate** \u003chttps://github.com/arayate\u003e\n- **xtrntr** \u003chttps://github.com/xtrntr\u003e\n- **mike1703** \u003chttps://github.com/mike1703\u003e\n- **themeewa** \u003chttps://github.com/themeewa\u003e\n\n## Change log\n\nGo to https://github.com/jarrekk/imgkit/wiki/CHANGE-LOG.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarrekk%2Fimgkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjarrekk%2Fimgkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarrekk%2Fimgkit/lists"}