使用ruby VIP将远程映像合并为一个映像
我有一个模板图像,需要在其上附加X,Y位置上的特定图像。rmagick中是否有与该函数等价的函数使用ruby VIP将远程映像合并为一个映像,ruby,image-processing,rmagick,vips,Ruby,Image Processing,Rmagick,Vips,我有一个模板图像,需要在其上附加X,Y位置上的特定图像。rmagick中是否有与该函数等价的函数 ImageList.new(“https://365psd.com/images/istock/previews/8479/84796157-football-field-template-with-goal-on-top-view.jpg“” 并利用其他图像生成一个图像。ruby VIP不支持直接从URI加载,因此需要使用其他gem获取图像。例如: require 'open-uri' requi
ImageList.new(“https://365psd.com/images/istock/previews/8479/84796157-football-field-template-with-goal-on-top-view.jpg“”
并利用其他图像生成一个图像。ruby VIP不支持直接从URI加载,因此需要使用其他gem获取图像。例如:
require 'open-uri'
require 'vips'
def new_from_uri(uri, options = {})
bytes = open(uri) {|f| f.read}
Vips::Image.new_from_buffer bytes, "", options
end
a = new_from_uri "https://upload.wikimedia.org/wikipedia/commons/a/a6/Big_Ben_Clock_Face.jpg"
b = new_from_uri "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"
out = a.composite b, "over", x: 100, y: 100
out.write_to_file "x.jpg"
使:
考虑使用块形式的
打开uri
,否则它不会立即关闭连接<代码>打开(url和:读取)