Showing posts with label scrot. Show all posts
Showing posts with label scrot. Show all posts

Monday, October 17, 2011

scrot 之 imgur 上传脚本

~/code/shell/shoot.html
#!/bin/bash

###################
# 截图上传imgur脚本
# 用法 $ shoot
# 
####################
#
# 依赖 scrot curl zenity xclip
#
# #################
#
# ps:注册自己的key,在这个地方 http://api.imgur.com/ ,一般来说选择 Anonymous API ,打开 http://imgur.com/register/api_anon
# 网站,填写相关信息后就会得到一串数字,替换掉上面的”key”=”5d317f0bee23b282473522e1aa68f621″ 中间的那一串数字即可。
# 这个 api是一个小时内允许上传五十张图,至于其他的,有兴趣的可以自己看看
#
# 参考: http://www.leyle.com/archives/342001
#       http://ubuntuforums.org/showthread.php?t=1604604
#       http://www.webupd8.org/2010/01/scripts-to-take-screenshot-and-upload.html
#       http://blog.felixc.at/2011/07/scrot-screenshot-script-auto-upload-to-imgur-and-copy-link/
#####################

screenshot='screenshot';
name=`date '+%Y-%m-%d-%H-%M-%S'`;
extension='.png';
#file="$HOME/Desktop/$screenshot-$nano$extension";
file="$HOME/Pictures/Shot/$screenshot-$name$extension";

sleep 0.2;

scrot -s -b $file;
#scrot -s -b -q 0 $file;

# curl使用proxy代理,比如我的ssh代理
TEXT=$(curl --socks5-hostname 127.0.0.1:7070 -F "image"=@"$file" -F "key"="c61f8914057660b4ede49a9975b2e57c" http://imgur.com/api/upload.xml | grep -Eo '<[a-z_]+>http[^<]+'|sed 's/^<.\|_./\U&/g;s/_/ /;s/<\(.*\)>/\1:\ /');

zenity --info --title="Imgur Upload" --text="$TEXT";

exit 0

#function uploadImage {
#  curl -s -F "image=@$1" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml | grep -E -o "<original_image>(.)*</original_image>" | grep -E -o "http://i.imgur.com/[^<]*"
#}
#
#scrot -s "shot.png" 
#uploadImage "shot.png" | xclip -selection c
#rm "shot.png"
#notify-send "Done"
#

#name=`date '+%Y-%m-%d-%H-%M-%S'`;
#
#extension='.png';
#
#file="$HOME/Pictures/Shot/$name$extension";
#
#sleep 0.2;
#
#scrot -s -b $file ;
#
#UPLODAD=$(curl --socks5-hostname 127.0.0.1:7070 -F "image"=@"$file" -F "key"="c61f8914057660b4ede49a9975b2e57c" http://imgur.com/api/upload.xml | grep -Eo '<original_image>(.+?)</original_image>' | grep -Eo 'http://(.+?).png');
#
#echo $UPLOAD | xclip -selection clipboard;
#
#echo $UPLOAD | xclip;
#
#zenity --info --title="Imgur Upload" --text="$TEXT";
##firefox $UPLOAD;
#
#echo "$name$extension $UPLOAD" >>  "$HOME/Pictures/Shot/.caphistory";
#
#notify-send -t 3000 "capture and update done"

Tuesday, October 11, 2011

scrot howto

截图软件 scrot 安装
pacman -S scrot

一般用法,就一般而言,使用 scrot 可以抓取整个桌面、某个指定的窗口、以及选择的矩形区域。
  1. 抓取桌面:scrot desktop.png,该命令将当前的整个桌面抓取下来,并保存为 desktop.png 文件。可以在当前的目录中找到此图像文件。
  2. 抓取窗口:scrot -bs window.png,选项 b 使 scrot 在抓取窗口时一同将外边框抓取下来,而 s 选项则让用户选择所要抓取的是何窗口。
  3. 抓取区域:scrot -s rectangle.png,在执行此命令后,使用鼠标拖曳的矩形区域将被 scrot 抓取下来。
高级使用,对于普通的抓取使用 scrot 的基础便足以应付了。但在某些特殊情况之下,使用 scrot 抓取图像需要讲究一些技巧。
  1. 延时抓取:scrot -cd 10 menu.png,此命令中的 d 选项用于延时抓取图像,其后的 10 代表延时 10 秒;前面的选项 c 显示倒计时。在抓取菜单或是命令提示时,该技巧将充分展示其魔力。
  2. 生成缩图:scrot -t 50% thumb.png,这个命令在抓取图像的同时生成该图像的缩略图。选项 t 将打开此功能,其后的 50% 为原图的缩放百分比。
  3. 更改品质:scrot -q 70 quality.jpg,此命令中的 q 选项用于更改所抓图像的品质,其数值介于 1-100 之间,默认为 75。数值越大,意味着图像品质越高;同时,图像的压缩率也就越低,占用空间越大。
  4. 操作抓图:scrot action.png -e 'mv $f ~/images/',该命令将抓取的图像移动到 ~/images/ 目录。显然,操作图像的功能由 e 选项开启,其中的 $f 代表原图的路径/文件名。