用于截取屏幕截图并保存图像的 Bash 脚本 - Ubuntu

Pra*_* Kl 6 command-line bash capture

我写了一个bash脚本如下:

#!/bin/bash
echo "Enter a file name"
read filename
import -window root $HOME/Desktop/$filename.png
Run Code Online (Sandbox Code Playgroud)

我希望这个脚本能够截取屏幕并将图像以给定的文件名保存在我的桌面上。

问题:我的 Ubuntu 终端出现错误:

导入:找不到命令

dev*_*av2 9

您需要安装包imagemagic才能使用 import 命令,通过 Ubuntu 软件中心或:

sudo apt-get install imagemagick
Run Code Online (Sandbox Code Playgroud)

这将允许您使用import命令。还可以尝试graphicsmagick-imagemagick-compat包。

进口的其他替代方案是


Anw*_*war 5

你可以用最好的截图工具 快门 安装百叶窗 也可用于脚本!而且我相信,这是最强大的工具,可为您提供最先进和微调的选项以在脚本中使用。

在终端中使用命令安装它

sudo apt-get install shutter
Run Code Online (Sandbox Code Playgroud)

或使用软件中心(通过单击下面的大按钮)

通过软件中心安装

安装后,使用此命令对整个显示进行截图并将截图保存在名为的文件中, myshot.png

shutter -f -o myshot.png -e
Run Code Online (Sandbox Code Playgroud)
  • -f告诉快门取整显示器的屏幕截图。您还可以-a用来截取活动窗口的屏幕截图,或告诉它从任何特定窗口进行截图。

  • -o选项用于告诉快门输出文件名。您可以指定任何文件名

  • 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.
Run Code Online (Sandbox Code Playgroud)