图像剪贴板

图像剪贴板

我经常阅读一些带有图像的文本,并且经常会发生文本谈论下一页和下一页和上一页上的图像的情况,我必须来回前进,并且通常忘记我在哪里暂停阅读。

我有一个想法将图像保存到图像剪贴板,该剪贴板能够包含大约 5 个图像(例如,制作屏幕区域的小屏幕截图)。在阅读时,当文本显示“参见图 10.4(第 42 页)”并在几秒钟内“将其与图 10.2(第 40 页)进行比较”时,我可以仅按键盘快捷键并选择所需的图片,而无需浏览文本。

这在 X Window 系统中可能吗?或者用一些脚本?

答案1

您也许可以用这个做一些事情..
它允许您在临时目录中收集图像(每个图像单击两次鼠标),scriptname -c...然后在轻量级图像查看器中显示图像,可以通过以下方式轻松导航光标键;scriptname -s
它将始终以最新的图像开始显示。如果您确实想将其限制为 5,那么您可以调整脚本,但它们位于 /tmp 中,并且经常会被清除。
只需将scriptname -c和分配scriptname -s给您选择的快捷键即可。我用来xbindkeys绑定我的快捷键。

#!/bin/bash
#
# Run $ script  [-c | -s] 
#    
# Uses:  grabc     GRAB Colour - screen pixel colour
#                  Allows you to position amd click the mouse. 
#                  The actual co-ordinates capture is done by xdotool.
#        xdotool   simulate X11 keyboard/mouse input
#        scrot     SCReen shOT - screen capture
#        pnmtopng  (from package 'netpbm') convert format  
#        display   (from package 'imagemagick') display single image  
#        eog        Eye Of Gnome - to display images forward and backwards
#
# Note: The area selection requires two distinct mouse clicks
#       First click the top-left corner, then the bottom-right corner
#       It is not a click-and-drag style of selection.
#

bname="$(basename "$0")"
oudir="/tmp/$USER/$bname"; [[ -d "$oudir" ]] || mkdir -p "$oudir"

case "$1" in 
 -s) # show images
     eog "$(find "$oudir" -maxdepth 1 -type f -name 'screen.20[0-9][0-9]-*.png' \
            |sort |tail -n 1)"
   ;;
  *) # capture image and save to output dir
     grabc 1>/dev/null  2>/dev/null; eval $(xdotool getmouselocation --shell); L=$X; T=$Y
     grabc 1>/dev/null  2>/dev/null; eval $(xdotool getmouselocation --shell); R=$X; B=$Y
     ((R<L||B<T)) && { echo "ERROR: invalid rectangle selected" 1>&2; exit 1; }
     scrot "$oudir/screen.pnm"
     oupic="$oudir/screen.$(date '+%Y-%m-%d %H:%M:%S').png"
          <"$oudir/screen.pnm" pnmcut -left $L -top $T -bottom $B -right $R \
          | pnmtopng > "$oupic"
            display    "$oupic" # for a quick preview.
   ;;
esac
#  

答案2

最初的 X Window 系统只有 X11 选择,即纯文本。有多种扩展可以实现剪贴板,但使用它们的应用程序彼此并不完全兼容。

您可以使用 Gimp 作为剪贴板,而不是使用 X11 剪贴板。您可以启动 Gimp,然后调用 gimp-remote 来加载图像。您还可以尝试 Gimps 粘贴功能是否与您的应用程序兼容。

此外,您可以启动 Script-Fu 服务器。默认端口为 10008。此后您可以向服务器发送 Script-Fu 命令。例如,这会创建一个新图像:

CMD='(gimp-display-new (car (gimp-image-new 300 200 0)))'
echo -e $(printf 'G\\0000\\%0.4o%s' ${#CMD} "$CMD") | nc -q1 localhost 10008

这种方法需要一些额外的编程来实现您所请求的功能。但应该是可能的。

答案3

克斯拉尔夫问道:

我有一个想法将图像保存到图像剪贴板
[...]
这在 X Window 系统中可能吗?

Unix 讨厌者手册

ICCCM 合规性是实现 X 工具包、窗口管理器甚至简单应用程序时最复杂的考验之一。这非常困难,以至于许多好处根本不值得遵守法规的麻烦。当一个程序不符合规定时,就会搞砸其他程序。这就是剪切和粘贴在 X 上无法正常工作的原因(除非您剪切并粘贴直接 ASCII 文本)

那些讨厌 Unix 的人说得有道理——我可以想象这类事情可能导致 Apple 选择不在 OSX 中使用 X-windows。

相关内容