The scenario is to run the program inside of Ubuntu VPS. Input a URL the program will output the jpg file.
The solution is to use wkhtmltoimage, which is a part of wkhtmtopdf.
I used to use the old version wkhtmltopdf v0.12.3. Now it is not working anymore due to some reason I don’t know.
But the wkhtmltopdf v0.12.5 is OK.
The OS is Ubuntu 18.04.
Then I install wkhtmltopdf with the following command
sudo apt-get install -y software-properties-common sudo apt-add-repository -y "deb http://security.ubuntu.com/ubuntu xenial-security main" sudo apt-get -yq update sudo apt-get install -y libxrender1 libfontconfig1 libx11-dev libjpeg62 libxtst6 fontconfig xfonts-75dpi xfonts-base libpng12-0 libjpeg-turbo8 wget "https://downloads.wkhtmltopdf.org/0.12/0.12.5/wkhtmltox_0.12.5-1.xenial_amd64.deb" sudo dpkg -i wkhtmltox_0.12.5-1.xenial_amd64.deb sudo apt-get -f install
After installation, run the command to show the help of the program.
Now I am going to render an image from the most famous web site.
The URL is https://www.google.com
Run the following command to generate the screenshot.
wkhtmltoimage --javascript-delay 3500 --height 768 --quality 64 "https://www.google.com" /home/davidyin/google.jpg