HtmlWebShot - A python3 package which Can Create Images From url, Html-CSS, Svg and from any readable file and texts with many setup features.

Overview

HtmlWebShot

PyPI version Codacy Badge Licencse PyPI downloads

A python3 package which Can Create Images From url, Html-CSS, Svg and from any readable file and texts with many setup features.

Setup & Installation

  • Install HtmlWebShot:

    $ pip3 install htmlwebshot
  • Install wkhtmltopdf:

    • Debian/Ubuntu:
      $ apt-get install wkhtmltopdf -y  
    • MacOs:
      $ brew install homebrew/cask/wkhtmltopdf
    • Alternative Support
      $ wget https://github.com/1Danish-00/HtmlWebShot/raw/main/script.sh | sh
      
    • Win / Arch / Others
      click here

Usage

Import & Instantiate

from htmlwebshot import WebShot
shot = WebShot()
Multiple Arguments
  • size: (int , int) : tuple : height, width default: full-screen
  • quality: int : between 1 to 100
  • delay: float : delay time in sec to load page
  • flags: list : know More
  • params: dict : know more
  • config: path setup know more

Simple Method

Using Url

shot.create_pic(url="https://google.com")

Using Html File

shot.create_pic(html="myfile.html", output="picture.jpg")

Using Html with CSS

via files

shot.create_pic(html="myfile.html", css="background.css", output="picture.jpg")

via string

Hello World

Write something about the world.

""" css = "body {background: pink;} p {color: red;}" shot.create_pic(html=html, css=css, output="picture.jpg") ">
html = """

Hello World

Write something about the world.

"""
css = "body {background: pink;} p {color: red;}" shot.create_pic(html=html, css=css, output="picture.jpg")

Using Svg Or Any Other Readable File/Text

shot.create_pic(other="violin.svg", output="picture.jpg")
text = "What should I write here???"
shot.create_pic(other=text, size=(100,200))

You can use with async too

await shot.create_pic_async( # parameters are same for both

Some Examples

Hello World

Write something about the world.

""" css = "body {background: pink;} p {color: red;}" shot.create_pic(html=html, css=css, output="picture.jpg") ">
from htmlwebshot import WebShot
shot = WebShot()

shot.size = (110, 270)
shot.quality = 80  # maximum 100

html = """

Hello World

Write something about the world.

"""
css = "body {background: pink;} p {color: red;}" shot.create_pic(html=html, css=css, output="picture.jpg")
Click Here To See Output Image Of Above Code. sample1
from htmlwebshot import WebShot
shot = WebShot()

shot.quality = 100
shot.params = {"--crop-x":300, "--crop-w": 400}

shot.create_pic(html="profile.html", css="profile.css")
Click Here To See Output Image Of Above Code. sample2

Click For More Examples
from htmlwebshot import WebShot
shot = WebShot()

shot.quality = 85
shot.flags = ["--enable-javascript"]

shot.create_pic(html="jsgraph.html")
Click Here To See Output Image Of Above Code. sample4
from htmlwebshot import WebShot
shot = WebShot()

shot.flags = ["--quiet"]
shot.quality = 100

shot.create_pic(other="violin.svg", size=(500,600))
Click Here To See Output Image Of Above Code. sample3

Flags Uses

Click Here To Check All Flags:
  • --quiet: Be less verbose
  • --disable-smart-width: To force size to be accurate
  • --custom-header-propagation: Add HTTP headers specified by flag --custom-header for each resource request
  • --no-custom-header-propagation: Don't Add HTTP headers specified by flag --custom-header for each resource request
  • --disable-javascript: Don't allow web pages to run javascript
  • --enable-javascript: Allow web pages to run javascript
  • --proxy-hostname-lookup: Use the proxy for resolving hostnames
  • --stop-slow-scripts: Stop slow running javascripts
  • --no-stop-slow-scripts: Don't Stop slow running javascripts
from htmlwebshot import WebShot
shot = WebShot()
shot.flags = ["--quiet", "--enable-javascript", "--no-stop-slow-scripts"]

Available Params

Click Here To Check All Params options:
  • --bypass-proxy-for: Bypass proxy for host (repeatable)
  • --cookie: Set an additional cookie (repeatable), value should be url encoded.
  • --cookie-jar: Read and write cookies from and to the supplied cookie jar file
  • --crop-h: Set height for cropping
  • --crop-w: Set width for cropping
  • --crop-x: Set x coordinate for cropping
  • --crop-y: Set y coordinate for cropping
  • --custom-header: Set an additional HTTP header (repeatable)
  • --encoding: Set the default text encoding, for input
  • --format: Output file format
  • --minimum-font-size: Minimum font size
  • --password: HTTP Authentication password
  • --post: Add an additional post field (repeatable)
  • --post-file: Post an additional file (repeatable)
  • --proxy: Use a proxy
  • --run-script: Run this additional javascript after the page is done loading (repeatable)
  • --ssl-crt-path: Path to the ssl client cert public key in OpenSSL PEM format, optionally followed by intermediate ca and trusted certs
  • --ssl-key-password: Password to ssl client cert private key
  • --ssl-key-path: Path to ssl client cert private key in OpenSSL PEM format
  • --user-style-sheet: Specify a user style sheet, to load with every page
  • --username: HTTP Authentication username
  • --window-status: Wait until window.status is equal to this string before rendering page
  • --zoom: Use this zoom factor
from htmlwebshot import WebShot
shot = WebShot()
shot.params = {
    "--custom-header": "Accept-Encoding gzip",
    "--minimum-font-size": 50,
    "--format": "png",
    "--zoom": 10,
    }

Config Path

If you installed pkg directly then no need to configure it, It'll auto configure.
But If u installed externally then you have to setup config path.

from htmlwebshot import WebShot, Config
shot = WebShot()
shot.config = Config(wkhtmltopdf="/path/to/wkhtmltopdf", wkhtmltoimage="/path/to/wkhtmltoimage")
You might also like...
A simple programme for converting url into a qr code (.png file)
A simple programme for converting url into a qr code (.png file)

QrTk A simple lightweight programme for converting url into a qr code (.png file) Pre-Requisites Before installing the programme , you need to run the

missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.
missing-pixel-filler is a python package that, given images that may contain missing data regions (like satellite imagery with swath gaps), returns these images with the regions filled.

Missing Pixel Filler This is the official code repository for the Missing Pixel Filler by SpaceML. missing-pixel-filler is a python package that, give

Snowfall - helpful image handling utils - abstracts various file and opencv and pil features into result oriented functions
Snowfall - helpful image handling utils - abstracts various file and opencv and pil features into result oriented functions

snowfall helpful image handling utils - abstracts various file and opencv and pil features into result oriented functions usage examples: from image_h

Xmas-Tree-GIF-Tool - Convert any given animated gif file into an animation in GIFT CSV format

This repo is made to participate in Matt Parker's XmasTree 2021 event. Convert a

A collection of python scripts which help you programatically create PNGs or GIFs
A collection of python scripts which help you programatically create PNGs or GIFs

A collection of python scripts which help you programatically create PNGs or GIFs and their Metadata in bulk with custom rarity rates, upload them to OpenSea & list them for sale.

A python based library to help you create unique generative images based on Rarity for your next NFT Project
A python based library to help you create unique generative images based on Rarity for your next NFT Project

Generative-NFT Generate Unique Images based on Rarity A python based library to help you create unique generative images based on Rarity for your next

📷 Python package and CLI utility to create photo mosaics.
📷 Python package and CLI utility to create photo mosaics.

📷 Python package and CLI utility to create photo mosaics.

Transfers a image file(.png) to an Excel file(.xlsx)
Transfers a image file(.png) to an Excel file(.xlsx)

Transfers a image file(.png) to an Excel file(.xlsx)

This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

Comments
  • [BUG REPORT]: Query String on Local File Not Working

    [BUG REPORT]: Query String on Local File Not Working

    Your System?

    Windows 10

    Version

    3.8

    Version

    latest

    What happened?

    When I try to take a screenshot of a local file whilst providing a URL query string, it does not work. My assumption is that it tried to look for a file which contains the query string in the filename.

    Paste Your Codes.

    shot.create_pic(html=r"folder\file.html?username=hi", css=r"folder\tweet.css", output="output.jpg")
    

    Your Error Logs.

    It does not output an error
    
    bug 
    opened by i-vone 3
  • [BUG REPORT]:

    [BUG REPORT]:

    Your System?

    Ubuntu

    Python Version

    3.8

    HtmlWebShot Version

    latest

    What happened?

    Delay not working at all

    Used Code.

    //tried this
    shot.params = {"--javascript-delay": 5000}
    //and this
    shot.create_pic(html="file.html", delay=5, output="out.jpg", size=(1024,512))
    //none worked?
    

    Error Logs.

    No response

    bug 
    opened by asauce0972 1
Releases(v0.1.0)
HTML2Image is a lightweight Python package that acts as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

A package acting as a wrapper around the headless mode of existing web browsers to generate images from URLs and from HTML+CSS strings or files.

null 176 Jan 1, 2023
An API that renders HTML/CSS content to PNG using Chromium

html_png An API that renders HTML/CSS content to PNG using Chromium Disclaimer I am not responsible if you happen to make your own instance of this AP

null 10 Aug 8, 2022
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

TroJanzHEX 44 Nov 17, 2022
Png-to-stl - Converts PNG and text to SVG, and then extrudes that based on parameters

have ansible installed locally run ansible-playbook setup_application.yml this sets up directories, installs system packages, and sets up python envir

null 1 Jan 3, 2022
Convert the SVG code to PNG and replace the line by a call to the image in markdown

Convert the SVG code to PNG and replace the line by a call to the image in markdown

null 6 Sep 6, 2022
A tool and a library for SVG path data transformations.

SVG path data transformation toolkit A tool and a library for SVG path data transformations. Currently it supports a translation and a scaling. Usage

Igor Mikushkin 2 Mar 7, 2022
将位图转为彩色矢量 svg 图片

一个将位图描摹为彩色矢量 svg 图片的程序,是一个命令行工具,使用 Python 脚本实现,运行环境 Python3.8+。 ✨ 效果 以一个字帖图片为例,这是 png 格式的位图(370KB): 这是颜

Haujet Zhao 104 Dec 30, 2022
🛹 Turn an SVG into an STL for stencil creation purposes

svg2stl This repository provides a script which takes as input an SVG such as this one: It outputs an STL file like this one: You can also see an inte

Max Halford 3 Dec 29, 2021
Collection of SVG diagrams about how UTF-8 works

Diagrams Repository of diagrams made for articles on my blog. All diagrams are created using diagrams.net. UTF-8 Licenses Copyright 2022 Seth Michael

Seth Michael Larson 24 Aug 13, 2022