
HTML (HyperText Markup Language) is the standard format for web pages. Sometimes you need to turn an HTML file into an image like JPG, PNG, TIFF, BMP, or GIF. This article shows how to convert HTML to PNG, JPEG, BMP, GIF, or TIFF images in Python.
- Python API to Convert HTML to Image
- Convert HTML to JPG Image
- Convert HTML to PNG Image
- HTML to BMP Conversion
- Convert HTML to GIF Image
- Convert HTML to TIFF Image
- HTML String to Image Conversion
Python API to Convert HTML to Image
We use the Aspose.Words for Python API to convert HTML to image formats. It provides full document handling, conversion, rendering, and printing for Word, PDF, and web documents.
Please install the API from PyPI using the following pip command in the console:
> pip install aspose-words
Info: If you already have Aspose.Slides for Python, you can use this API to convert HTML to image, convert HTML to PDF, convert HTML to PPT, convert HTML to JPG, convert HTML to XML, and convert HTML to TIFF. Similarly, it allows you to import HTML from PPT, get it from PDF, etc.
Convert HTML to JPG Image in Python
We can easily convert HTML documents to JPG images by following these steps:
- Load the HTML file using the Document class.
- Optionally, specify image save options with the ImageSaveOptions class.
- Loop through all pages in the document.
- Extract each page using the extract_pages() method.
- Save each page as JPG using the save() method.
The following code sample shows how to convert HTML to JPG images in Python.

Convert HTML to PNG Image in Python
We can convert HTML documents to PNG images by following these steps:
- Load the HTML file using the Document class.
- Create an ImageSaveOptions instance.
- Set options such as image_brightness and image_contrast.
- Loop through all pages in the document.
- Extract each page with extract_pages().
- Save each page as PNG using the save() method.
The following code sample shows how to convert HTML to PNG images in Python.
HTML to BMP Conversion in Python
We can convert HTML documents to BMP images by following these steps:
- Load the HTML file using the Document class.
- Loop through all pages in the document.
- Extract each page with extract_pages().
- Save each page as BMP using the save() method.
The following code sample shows how to convert HTML to BMP images in Python.
Convert HTML to GIF Image in Python
Similarly, we can convert HTML documents to GIF images. Use the same steps as above and save the files with a “.gif” extension in step 4.
The following code sample shows how to convert HTML to GIF images in Python.
Convert HTML to TIFF Image in Python
We can also convert HTML documents to TIFF images by following these steps:
- Load the HTML file using the Document class.
- Save the document as TIFF with the save() method.
The following code sample shows how to convert an HTML document to a TIFF image in Python.

HTML String to Image Conversion in Python
We can generate an image from an HTML string dynamically by following these steps:
- Create a Document instance.
- Create a DocumentBuilder instance.
- Insert the HTML string using insert_html().
- Save the document as JPG with the save() method.
The following code sample shows how to convert an HTML string to a JPG image in Python.

Get a Free License
You can get a free temporary license to try Aspose.Words for Python without evaluation limitations.
Conclusion
In this article, we learned how to:
- Convert HTML documents to images programmatically;
- Transform HTML files into PNG, JPEG, BMP, GIF, or TIFF images;
- Generate an HTML document and convert it into an image using Python.
You can explore more details in the documentation. For questions, visit the forum.