(注意这是一个非常古老的答案,并在两个主要版本之前描述了 ruby-vips。我已将其更新为 2.0.16 gem,即 2019 年 11 月的当前版本)
这里有完整的文档:
https://rubydoc.info/gems/ruby-vips
该Vips
部分有一个教程式的介绍:
https://rubydoc.info/gems/ruby-vips/Vips
例如:
require 'vips'
if ARGV.length < 2
raise "usage: #{$PROGRAM_NAME}: input-file output-file"
end
im = Vips::Image.new_from_file ARGV[0], access: :sequential
im *= [1, 2, 1]
mask = Vips::Image.new_from_array [
[-1, -1, -1],
[-1, 16, -1],
[-1, -1, -1]
], 8
im = im.conv mask, precision: :integer
im.write_to_file ARGV[1]
这将以流模式打开图像,将中间波段(绿色)乘以 2,使用整数卷积锐化图像,并将结果写回。你可以像这样运行它:
./example.rb x.jpg y.ppm
ruby-vips repo 中有一个完整的“daltonize”示例:
https://github.com/libvips/ruby-vips/blob/master/example/daltonize8.rb