Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
To convert HTML to an image in Python, pass an HTML file,
HTMLDocument, or
Url to
Converter.convert_html() with
ImageSaveOptions and an output path. Select PNG, JPEG, GIF, BMP, TIFF, or WebP with ImageFormat.
HTML-to-image conversion renders HTML and CSS as static raster output. It is useful for webpage previews, thumbnails, reports, documentation, and content snapshots. The resulting images do not preserve the interactivity of links or form controls, or other HTML behavior.
HTMLDocument, or a Url.ImageSaveOptions and select the required ImageFormat.Converter.convert_html() with the source, options, and output path.The following example converts banner.html to WebP and explicitly selects the output format:
1import os
2import aspose.html.converters as conv
3import aspose.html.rendering.image as rim
4import aspose.html.saving as sav
5
6input_dir = "data"
7output_dir = "output"
8os.makedirs(output_dir, exist_ok=True)
9
10input_path = os.path.join(input_dir, "banner.html")
11output_path = os.path.join(output_dir, "banner.webp")
12
13options = sav.ImageSaveOptions(rim.ImageFormat.WEBP)
14conv.Converter.convert_html(input_path, options, output_path)The example reads the HTML file, selects ImageFormat.WEBP, and writes banner.webp. To create another raster format, use the corresponding ImageFormat value and a matching output extension.
Choose the output format according to the source content and required image characteristics:
| Format | ImageFormat value | Use it for |
|---|---|---|
| PNG | ImageFormat.PNG | Lossless output, text, diagrams, interface previews, and transparency. PNG is the default format. |
| JPEG | ImageFormat.JPEG | Photographs and smaller lossy files when transparency is not required. |
| GIF | ImageFormat.GIF | Static graphics with a limited color palette. HTML-to-GIF conversion does not capture animation frames. |
| BMP | ImageFormat.BMP | Bitmap workflows where broad compatibility is more important than file size. |
| TIFF | ImageFormat.TIFF | Image workflows that require TIFF output and configurable TIFF compression. |
| WebP | ImageFormat.WEBP | Web-oriented raster output with efficient compression. |
Use .png, .jpg or .jpeg, .gif, .bmp, .tif or .tiff, and .webp extensions so that the file name matches the selected format. For format-specific examples, see
Convert HTML to PNG,
Convert HTML to JPEG, and
Convert HTML to GIF.
ImageSaveOptions controls the selected image format and the shared rendering settings used during HTML-to-image conversion.
| Property | Use it to control |
|---|---|
| format | Output image format. The default is PNG. |
| page_setup | Output page size, margins, and pagination. |
| horizontal_resolution and vertical_resolution | Resolution of output pages defined in physical units and internal raster images used during processing. The default is 300 dpi. |
| background_color | Background color of each output page. The default is transparent. |
| css | CSS processing settings, including the media type used during rendering. |
| use_antialiasing | Smoothing of rasterized edges. It is enabled by default. |
| text | Text-rendering settings, including font hinting. |
| compression | TIFF compression. It does not set JPEG quality. |
When a page is defined in pixels, its width and height determine the output raster dimensions directly. When a page is defined in physical units such as millimeters or inches, the horizontal and vertical resolution determine the resulting pixel dimensions. Increasing DPI does not enlarge a page whose dimensions are already specified in pixels.
| Problem | Check or fix |
|---|---|
| The image has unexpected page dimensions | Configure page_setup.any_page.size. Default page settings can produce a document-sized image rather than a tightly cropped screenshot. |
| Conversion creates several numbered files | The rendered content spans multiple output pages. Adjust the page size or source layout when a single image is required. |
| Text or images look blurred | Increase the actual output pixel dimensions and use sufficiently detailed source images. DPI does not enlarge a page already defined in pixels. |
| CSS, images, or fonts are missing | Ensure relative URLs resolve against the document location or base URI and that linked resources are accessible. |
| URL conversion takes a long time | Check for large, slow, or unavailable linked resources. Use a stable URL that the application can access. |
| Colors or transparency differ from the source | Check the selected output format. JPEG has no transparency, while GIF has a limited palette and no partial alpha transparency. |
Yes. Create a Url, select the required image format with ImageSaveOptions, and pass the URL, options, and output path to Converter.convert_html(). The application must be able to access the webpage and its linked resources.
It creates a static rendered image of the HTML document using the configured page and rendering options. It does not capture browser controls, user interaction, or a sequence of animation frames.
Image output is page-based. When the rendered HTML spans several pages, the converter creates an image for each page. Configure the page size or adjust the source layout when one output image is required.
Use the free online converter below for occasional manual conversion. For programmatic conversion, evaluate the library or follow the licensing guide to request a temporary license.
Use the free online HTML to Image Converter for quick manual conversion without writing code. Use Aspose.HTML for Python via .NET when image conversion must run in a Python application, service, or document-processing workflow.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.