Command line program to create website screenshots (on Linux)
A little more detail might be useful...
Start a firefox (or other browser) in an X session, either on your console or using a vncserver. You can use the --height
and --width
options to set the size of the window to full screen. Another firefox command can be used to set the URL being displayed in the first firefox window. Now you can grab the screen image with one of several commands, such as the "import" command from the Imagemagick package, or using gimp, or fbgrab, or xv.
#!/bin/sh
# start a server with a specific DISPLAY
vncserver :11 -geometry 1024x768
# start firefox in this vnc session
firefox --display :11
# read URLs from a data file in a loop
count=1
while read url
do
# send URL to the firefox session
firefox --display :11 $url
# take a picture after waiting a bit for the load to finish
sleep 5
import -window root image$count.jpg
count=`expr $count + 1`
done < url_list.txt
# clean up when done
vncserver -kill :11
Generating Website screenshots on CentOS using PHP
There are various commandline utilities available. Most start one of the browser engines in headless X11 and take a screenshot then. A particular common one is khtml2png
which can be used from php like this (not sure if there is a precompiled version for CentOS):
exec("khtml2png --width 800 --height 600 http://google.com/ img.png");
A few more are listed here: Command line program to create website screenshots (on Linux)
Linux: launch window, capture screen
It sounds like you'll need to use the "virtual framebuffer" driver for the X.org server, combined with the xwd, NetPBM, and cjpeg utilities.
I'm not sure about the particular configuration you'll need for the X server, but you will likely have to make sure the server you're using has the virtual framebuffer driver built into to. The virtual framebuffer driver is a display driver just like one you'd use to connect to an NVidia or ATI video card, except it's "output" is a chunk of memory that contains the pixels, not an LCD screen.
xwd is one of the standard X tools, that can create a X Window Dump. xwd can be told on the command line which window to dump. It outputs a funky "xwd" formatted stream to standard out.
The NetPBM utilities are a collection of command line tools that convert one image format to another. It includes one that converts xwdtoppm. PPM is a very basic, non-compressed format that is the intermediate format understood by most of the NetPBM tools.
cjpeg is part of the standard JPEG tools collection, and is probably installed if you also have NetPBM. cjpeg can take a stream of PPM bytes and emit a stream of JPEG bytes.
Through the magic of Unix scripting and pipes, you can string these utilities together to fire up the app with the window, call xwd, xwdtoppm, and cjpeg to dump the image to a file.
generate image (e.g. jpg) of a web page?
Try CutyCapt, a command-line utility. It uses Webkit for rendering and outputs in various formats (SVG, PNG, etc.).
Taking website screenshot, server-side, on a Linux rented server, free
PhantomJs is the solution
if(phantom.state.length === 0){
phantom.state = '0_home';
phantom.open('http://www.mini.de');
}
else if(phantom.state === '0_home'){
phantom.viewportSize = {width: 800, height: 600};
phantom.sleep(2000);
phantom.render('home.png');
phantom.exit(0);
}
Take a full page screenshot with Firefox on the command-line
The Developer Toolbar GCLI and Shift+F2 shortcut were removed in Firefox version 60. To take a screenshot in 60 or newer:
- press Ctrl+Shift+K to open the developer console (⌥ Option+⌘ Command+K on macOS)
- type
:screenshot
or:screenshot --fullpage
Find out more regarding screenshots and other features
For Firefox versions < 60:
Press Shift+F2 or go to Tools > Web Developer > Developer Toolbar to open a command line. Write:
screenshot
and press Enter in order to take a screenshot.
To fully answer the question, you can even save the whole page, not only the visible part of it:
screenshot --fullpage
And to copy the screenshot to clipboard, use --clipboard
option:
screenshot --clipboard --fullpage
Firefox 18 changes the way arguments are passed to commands, you have to add "--" before them.
Firefox 88.0 has a new method for taking screenshots. If extensions.screenshots.disabled
is set to false
in about:config, you can right-click the screen and select Take Screenshot. There's also a screenshot menu button you can add to your menu via customization.
You can find some documentation and the full list of commands here.
PS. The screenshots are saved into the downloads directory by default.
webpage screenshot khtml2png alternatives
http://www.paulhammond.org/webkit2png/
see this
with python
python /path/to/webkit2png http://www.google.com/
also you can do it with firefox !?
firefox -savepng http://www.web-screen-capture.com/
Related Topics
Automatically Capture Output of Last Command into a Variable Using Bash
How to Delete a Newline If It Is the Last Character in a File
How to Compile a 32-Bit Binary on a 64-Bit Linux Machine With Gcc/Cmake
How to Set Environment Variable For Everyone Under My Linux System
How to Run a Shell Script When a File or Directory Changes
Minimal Executable Size Now 10X Larger After Linking Than 2 Years Ago, For Tiny Programs
Bash Command Not Found When Setting a Variable
Free Git Server With Web Gui a La Bitbucket/Github
Linux Command to Print Directory Structure in the Form of a Tree
How to Access the System Call from User-Space
How to Deal With a Filename That Starts With the Hyphen (-) Character
How to Upgrade Glibc from Version 2.12 to 2.14 on Centos
Why Does /Bin/Sh Behave Differently to /Bin/Bash Even If One Points to the Other
How to Find Out Line-Endings in a Text File
Redirect Stderr/Stdout of a Process After It's Been Started, Using Command Line