art*_*bot 34 command-line clipboard
我想编写一个脚本来获取图像文件,将其缩放 50% 并将其放在剪贴板上,以便可以轻松粘贴。我遇到的问题是如何在剪贴板上放置图像。
我知道 xclip,但 AFAICS 只处理文本。如果没有生成它的应用程序坐在旁边,是否可以在剪贴板上放置图像?- 抱歉,我不确定剪贴板的工作原理!
感谢下面弗洛里安的回答,我能够实现我想要的,即截取屏幕截图并自动将其缩放到最大 600 像素宽(例如粘贴到电子邮件中)。我面临的另一个问题是 Thunderbird 不接受image/png剪贴板。我通过将其转换text/html为dataurl来解决这个问题。这是我的代码,以防有人发现它有用:
#!/bin/bash
TMP=/tmp/screenshot.png
function screenshotfail {
notify-send -u low -i image "Screenshot failed."
exit
}
# Take screenshot
gnome-screenshot -a -b -p -f "$TMP" || screenshotfail
# Ensure it's max 600px wide
mogrify -resize '>600x' "$TMP" || screenshotfail
# optimise the png if optipng is installed.
which optipng >/dev/null && optipng "$TMP"
# Copy to clipboard.
#
# This is what does not work for Thunderbird:
# xclip -selection clipboard -t image/png <"$TMP" || screenshotfail
# But this does:
echo "<img src='data:image/png;base64,"$(base64 -w0 "$TMP")"' />" | \
xclip -selection clipboard -t text/html || screenshotfail
# Remove the temp file.
rm -f "$TMP"
# Notify user.
notify-send -u low -i image "600px screenshot copied to clipboard"
Run Code Online (Sandbox Code Playgroud)
Flo*_*sch 50
使用该-t选项指定内容类型,例如
xclip -selection clipboard -t image/png -i example.png
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20081 次 |
| 最近记录: |