我已经尝试了Shutter。它能够正常工作,但是当我运行命令时会生成警告(
Wnck-WARNING **: Unhandled action type
)。我认为这个工具可能是设计用于GNOME环境,可能与Lubuntu不兼容。截图成功,但命令却挂起,这对我来说无法接受。那么有没有一个好的截图工具满足以下要求:
- 可以从命令行运行
- 可以捕捉桌面的特定区域
我想补充一下,Lubuntu附带的工具
scrot
没有裁剪特定坐标的选项,只能交互式地定义一个区域,这不是我想要的。Wnck-WARNING **: Unhandled action type
)。我认为这个工具可能是设计用于GNOME环境,可能与Lubuntu不兼容。截图成功,但命令却挂起,这对我来说无法接受。scrot
没有裁剪特定坐标的选项,只能交互式地定义一个区域,这不是我想要的。scrot_extended 100 100 400 400
使用下面的脚本。
四个参数是 <x>, <y>, <width>, <height>
。
我还没有在 Lubuntu 12.04
中测试过它,但似乎不太可能不起作用;它使用的是 python 2
和基本的命令行工具,这些工具已经存在很长时间了。
这个脚本:
scrot
进行截屏imagemagick
创建一个新的图像,根据你运行脚本时的参数进行裁剪脚本同时使用了scrot
和imagemagick
。确保你的系统上已经安装了scrot
。要安装imagemagick
,请执行以下命令:
sudo apt-get install imagemagick
将脚本复制到一个空文件中。
默认情况下,图像会保存在~/scrot_images
目录下,并以outputfile_1.png
、outputfile_2.png
等命名。如果需要更改保存路径,请按照脚本中的标记进行修改。注意,如果更改了目录,必须使用完整路径。
将文件保存到~/bin
目录中(如果需要,创建该目录),并将其命名为scrot_extended
(无扩展名),然后赋予可执行权限。
退出当前账户并重新登录,然后使用以下命令进行截屏:
scrot_extended <x> <y> <width> <height>
例子:
scrot_extended 100 100 400 400
输出文件:
#!/usr/bin/env python
import subprocess
import os
import sys
# setting default directories / filenames
home = os.environ["HOME"]
temp = home+"/"+".scrot_images"
img_in = temp+"/in.png"
# if you prefer, you can change the two line below:
output_directory = home+"/"+"scrot_images" # output directory
filename = "outputfile" # filename
# creating needed directories
for dr in [temp, output_directory]:
if not os.path.exists(dr):
os.mkdir(dr)
# creating filename (-number) to prevent overwriting previous shots
n = 1
while True:
img_out = output_directory+"/"+filename+"_"+str(n)+".png"
if os.path.exists(img_out):
n = n+1
else:
break
# reading arguments,arranging commands to perform
coords = sys.argv[1:5]
cmd1 = ["scrot", img_in]
cmd2 = ["convert", img_in, "-crop", coords[2]+"x"+coords[3]+"+"+coords[0]+"+"+coords[1], "+repage", img_out]
# Take screnshot, crop image
for cmd in [cmd1, cmd2]:
subprocess.call(cmd)
scrot /tmp/img-in.png -e "convert /tmp/img-in.png -crop 100X200+300+400 ~/Desktop/"$(date +%Y%m%d%H%M%S)".png"
这样的命令就足够了吗? - DK Bose使用maim
比使用scrot_extended的接受答案更容易。现在关于如何在maim
中获取固定大小截图的回答已经过时。
maim
允许您使用geometry(g)标志指定几何形状。如文档所述:
-g, --geometry=GEOMETRY
Sets the region to capture, uses local coordinates from the given
window. So -g 10x30-5+0 would represent the rectangle wxh+x+y where
w=10, h=30, x=-5, and y=0. x and y are the upper left location of this rectangle.
使用方法:
maim -g <w>x<h>+<x>+<y> <output-file>
例子:
maim -g 1024x1024+10+20 ~/test.png
slop
来交互式地获取这些几何坐标 - Anthonmaim
概述
maim
(make image)是一个新的截图工具,旨在作为scrot
的改进版本。
maim
带来的众多新功能之一是支持从命令行界面设置屏幕捕获区域。语法如下:
maim -x <x-coordinate> -y <y-coordinate> -w <width> -h <height>
e.g.:
maim -x 100 -y 100 -w 400 -h 400
安装
maim
还没有出现在官方软件仓库中,也不是任何 PPA 的一部分。您需要从源代码编译然后安装。
确保所有依赖项已满足后...
sudo apt-get install build-essential cmake
sudo apt-get install libimlib2-dev libxrandr-dev libxfixes-dev
git clone https://github.com/naelstrof/maim.git
cd maim
cmake ./
make && sudo make install
maim
了。请确保查看文档(maim --help
)以获取所有可用选项;还可以查看slop
,这是同一开发者的一个实用工具,可以让你交互式地选择屏幕截图的区域。当前版本的scrot具有截取屏幕上定义矩形的能力。
scrot --autoselect '1,2,3,4' outfile.png
# 在1,2处截取宽度为3,高度为4的矩形
当然,您需要将1,2替换为您想要的矩形的x、y像素坐标。因此,x、y将是您所需矩形的左上角像素。
还可以参考this answer以了解如何从bash脚本中获取当前鼠标坐标的说明。
这个脚本与Jacob Vlijm的答案几乎相同,但使用的是bash。它使用时间戳命名文件,以避免覆盖现有文件。它还允许您在脚本中定义默认的裁剪参数,因此您不需要使用任何参数来调用它。
按照以下方式调用下面的脚本(假设您在存储脚本的目录中,否则需要提供脚本的完整路径):
./screenshot.sh $left_px $top_px $width_px $height_px
或者./screenshot.sh
,此时将使用脚本中指定的默认参数。1)安装必要的应用程序
从命令行运行:
sudo apt install scrot imagemagick
left
和top
并计算width
和height
的鼠标坐标。#!/bin/bash
# Change these values to match your preferences
imageQuality=100 # scrot default is 75
screenshotDir="/tmp" # directory in which to save screenshots
imageName="$(date +%Y-%m-%d.%H:%M:%S.%N).jpg" # save image names as timestamp
default_left=10 # begin crop this number of pixels from the left of the image
default_top=10 # begin crop this number of pixels from the top of the image
default_width=100 # crop this many pixels wide
default_height=100 # crop this many pixels tall
#Do not make any more changes from here down unless you know what you're doing
l=$1; t=$2; w=$3; h=$4
left=${l:=$default_left}
top=${t:=$default_top}
width=${w:=$default_width}
height=${h:=$default_height}
imagePath="$screenshotDir/$imageName"
[ ! -d "$screenshotDir" ] && mkdir -p "$screenshotDir"
scrot -q $imageQuality "$imagePath"
convert "$imagePath" -crop ${width}x${height}+${left}+${top} "$imagePath"
screenshot.sh
,您可以在命令行中执行以下操作:
chmod +x /path/to/your/script/screenshot.sh
3) 将此脚本绑定到键盘快捷键 (可选)
按照此处找到的说明创建自定义键盘快捷键。当您需要输入命令时,请输入完整路径到您的screenshot.sh
文件(包括文件名)。xfce4-screenshooter
shutter
的--exit_after_capture
选项吗?此外,许多图形界面程序在命令行运行时会生成这样的警告。真的没什么好担心的。 - muru