Ruby-vips を使用してリモートイメージを 1 つのイメージに結合する
概要
テンプレート画像があったので、その上に X 、 Y 位置に特定の画像を追加する必要があります。 rmagick にその関数と同等のものはありますか
ImageList.new(“https://365psd.com/images/istock/previews/8479/84796157-football-field-template-with-goal-on-top-view.jpg”)
そして、その他の画像を描画して 1 つの画像を生成します。
解決策
次のように、ruby-vips で URI を読み書きできます。
#!/usr/bin/ruby
require "vips"
require "down"
def new_from_uri(uri)
byte_source = Down.open uri
source = Vips::SourceCustom.new
source.on_read do |length|
puts "reading #{length} bytes from #{uri} ..."
byte_source.read length
end
source.on_seek do |offset, whence|
puts "seeking to #{offset}, #{whence} in #{uri}"
byte_source.seek(offset, whence)
end
return Vips::Image.new_from_source source, "", access: :sequential
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"
コンソール出力を見ると、2 つのソース イメージがロードされ、ピクセルがインターリーブされていることがわかります。次の出力が行われます。
Vips::Source のドキュメントに詳細が記載されています。