Skip to content

Instantly share code, notes, and snippets.

@Rouhollah
Created March 5, 2020 09:15
Show Gist options
  • Save Rouhollah/485cbe528c02b48d7554812a780fd868 to your computer and use it in GitHub Desktop.
Save Rouhollah/485cbe528c02b48d7554812a780fd868 to your computer and use it in GitHub Desktop.
Convert Html Element To Image With Command Line And Google Chrome
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot=D:\Download\1\screen.png --window-size=1920,1280 --default-background-color=0 C:\Users\r.torshizi\Desktop\flexResponsive.html
@Rouhollah
Copy link
Author

i separate this code from this link .

description

  • given an html file, generate a (png) image with transparent background from the command

  • you run Chrome from the command line (here shown for the Mac, but assuming similar on Windows or Linux)

  • --headless runs Chrome without opening it and exits after the command

  • --screenshot will capture a screenshot (note that it generates a file called screenshot.png in the folder where the command is run)

  • --window-size allow to only capture a portion of the screen (format is --window-size=width,height)

  • --default-background-color=0 is the magic trick that tells Chrome to use a transparent background, not the default white color

  • finally you provide the html file (as a url either local or remote...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment