当前位置: 首页>>技术教程>>正文


什么是终端命令截图?

, ,

问题描述

我可以在相当于PrtSc(打印屏幕)按钮的终端中使用哪些命令?

我正在运行Ubuntu GNOME。

最佳解决方案

您可以使用ImageMagick软件包中提供的导入工具(如果您的系统上没有该软件,则需要安装该工具)。

Run the following command in a shell:

import screenshot.png 

and select the window you want to capture or select a region by pressing the left mouse button and dragging.

import is a actually a very powerful command which can be used in many ways to capture the screen. For example, to capture the entire screen and after some delay and resizing it, use the following command:

import -window root -resize 400x300 -delay 200 screenshot.png 

To see all the options available with import command, go to ImageMagick’s website.

从终端截取屏幕截图的另一种方法是用scrot

要安装scrot类型:

sudo apt-get install scrot

从scrot类型的终端在Linux中截取屏幕截图:

scrot MyScreenshot.png

scrot的更多选项如下:

scrot -b -d 5 '%Y:%m:%d:%H:%M:%S.png' -e 'mv $f ~/Desktop/'

在这个例子中,

  • -b指定包含窗口边框

  • -d指定延迟五秒

  • ‘%Y:%m:%d:%H:%M:%S.png’会根据当前的日期和时间以指定的格式保存截图,在这种情况下为.png

  • -e 'mv $f ~/Desktop/'通知scrot将屏幕截图保存到桌面

次佳解决方案

发现这个选项here和其他选项也列出。

Ctrl + Alt + T打开终端并键入

gnome-screenshot

使用gnome-screenshot -d xx来延迟操作。

将屏幕截图动作延迟10秒

gnome-screenshot -d 10

要么

sleep 10;gnome-screenshot

第三种解决方案

您可以使用快门程序从终端进行截图。运行终端中的以下命令安装快门,

sudo add-apt-repository ppa:shutter/ppa
sudo apt-get update
sudo apt-get install shutter

要获取活动窗口的屏幕截图,

shutter -a -o shot.png -e

要截取整个显示屏幕,

shutter -f -o shot.png -e

所拍摄的屏幕截图存储在主目录中。

要获得更多选项,请运行shutter --help命令,

Usage:
    shutter [options]

Options:
    Example 1
            shutter -a -p=myprofile --min_at_startup

    Example 2
            shutter -s=100,100,300,300 -e

    Example 3
            shutter --window=.*firefox.*

    Example 4
            shutter --web=http://shutter-project.org/ -e

  Capture Mode Options:
    -s, --select=[X,Y,WIDTH,HEIGHT]
            Capture an area of the screen. Providing X,Y,WIDTH,HEIGHT is
            optional.

    -f, --full
            Capture the entire screen.

    -w, --window=[NAME_PATTERN]
            Select a window to capture. Providing a NAME_PATTERN (Perl-style
            regex) ist optional.

    -a, --active
            Capture the current active window.

    --section
            Capture a section. You will be able to select any child window
            by moving the mouse over it.

    -m, --menu
            Capture a menu.

    -t, --tooltip
            Capture a tooltip.

    --web=[URL]
            Capture a webpage. Providing an URL ist optional.

    -r, --redo
            Redo last screenshot.

  Settings Options:
    -p, --profile=NAME
            Load a specific profile on startup.

    -o, --output=FILENAME
            Specify a filename to save the screenshot to (overwrites any
            profile-related setting).

            Supported image formats: You can save to any popular image
            format (e.g. jpeg, png, gif, bmp). Additionally it is possible
            to save to pdf, ps or svg.

            Please note: There are several wildcards available, like

             %Y = year
             %m = month
             %d = day
             %T = time
             $w = width
             $h = height
             $name = multi-purpose (e.g. window title)
             $nb_name = like $name but without blanks in resulting strings
             $profile = name of current profile
             $R = random char (e.g. $RRRR = ag4r)
             %NN = counter

            The string is interpretted by strftime. See "man strftime" for
            more examples.

            As an example: shutter -f -e -o './%y-%m-%d_$w_$h.png' would
            create a file named '11-10-28_1280_800.png' in the current
            directory.

  Application Options:
    -h, --help
            Prints a brief help message and exits.

    -v, --version
            Prints version information.

    -d, --debug
            Prints a lot of debugging information to STDOUT.

    --clear_cache
            Clears cache, e.g. installed plugins, at startup.

    --min_at_startup
            Starts Shutter minimized to tray.

    --disable_systray
            Disables systray icon.

    -e, --exit_after_capture
            Exit after the first capture has been made. This is useful when
            using Shutter in scripts.

第四种方案

我尝试使用ImageMagick import,但在使用KDE桌面效果时它不适用于我。 ImageMagick import以黑色输出透明窗口边框,而不是正确组合前景Alpha和背景。

我也试过使用X11 xwd和NetPBM xwdtopnm,但这也不适用于我,NetPBM xwdtopnm无法正确处理xwd的多画面输出,因为我有一个Xinerama设置。

但是将X11 xwd与ImageMagick convert结合起来对我来说工作得很好:

xwd -silent -root | convert xwd:- screenshot.png

或者,如果您有像我这样的Dual-FullHD Xinerama设置,并且只需要第一个屏幕:

xwd -silent -root | convert xwd:- -crop 1920x1080+0+0 test.png

仅用于第二个屏幕:

xwd -silent -root | convert xwd:- -crop 1920x1080+1920+0 +repage test.png

第五种方案

如果要从login-terminal(使用Ctrl + Alt + F1打开的那个)截取屏幕截图,可以使用程序fbgrab

您可以通过键入sudo apt-get install fbcat来安装它。

然后截取login-terminal的屏幕截图,输入login-terminal:

$ sudo fbgrab my_screenshot

my_screenshot保存在当前目录下。

第六种方案

我使用的是Ubuntu 13.10,我有一个我刚刚写的脚本,可能会有所帮助。我看到这个问题已得到解答,但我的解决方案无需额外安装。

#!/bin/bash
curDate=$(date)
imgExtension=".png"
imgName=$curDate$imgExtension
imgDirectory="/path/to/desires/save/directory/"
imgSavePath=$imgDirectory$imgName
gnome-screenshot --file="$imgSavePath"

此代码将保存屏幕截图而不弹出对话窗口。它使用当前时间作为文件名以避免任何重复的文件名问题。

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/556.html,未经允许,请勿转载。