简体   繁体   English

我应该将什么 gem 或外部程序与 Ruby 和 Linux 一起使用,以帮助选择图像?

[英]What gem or external program should I use with Ruby and Linux, to help to choose an image?

My Ruby script chooses a random image from a directory of photos, it then shows the chosen image to me, by simply calling "feh" image viewer.我的 Ruby 脚本从照片目录中选择一个随机图像,然后通过简单地调用“feh”图像查看器向我显示所选图像。 Currently I can't move on to a next photo, if needed: as the photo must suit somewhat to the music which was selected by the script earlier also randomly, and opened in a media player.目前,如果需要,我无法继续拍摄下一张照片:因为照片必须在某种程度上适合脚本先前随机选择并在媒体播放器中打开的音乐。 Which gem or even external program can I use for this purpose, which, if called, enables to step to a next random image, and waiting for me pressing Y or ESC to accept, or N for a next random image.我可以为此目的使用哪个 gem 或什至外部程序,如果调用它,可以进入下一个随机图像,并等待我按 Y 或 ESC 接受,或按 N 以获取下一个随机图像。

A tricky solution I found with feh:我用 feh 找到了一个棘手的解决方案:

ret=%x{feh -z --info "echo '%F' 1>&2" /path/to/images/* 2>&1}
last_image=ret.split("\n").last
puts "chosen image: "+last_image

Explanation: -z randomizes the file list, --info accept a command line which return value is shown on the image as info, eg.说明:-z 随机化文件列表,--info 接受一个命令行,其返回值在图像上显示为信息,例如。 exif data, size, etc. Currently it is a simple echo command echoing the actual file path, but redirecting its output to stderr from stdout. exif 数据、大小等。目前它是一个简单的回显命令,回显实际文件路径,但将其 output 从 stdout 重定向到 stderr。 This way the info isn't shown on the current image, but is simply printed to the STDERR.这样信息就不会显示在当前图像上,而只是打印到 STDERR。 At the end of the feh command line its stderr is redirected to stdout, so Ruby's %x command collects the printed lines.在 feh 命令行的末尾,它的 stderr 被重定向到 stdout,因此 Ruby 的 %x 命令收集打印的行。 After exiting feh, the "ret" variable contains all the printed lines, which were echoed by the --info hook.退出 feh 后,“ret”变量包含所有打印的行,这些行由 --info 挂钩回显。 The last one is the last image shown, which is the accepted image.最后一个是最后显示的图像,这是接受的图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM