-
I have two gifs: How can I make This is the code I'm currently using: require 'vips'
character = File.open("character.gif").read
character_b = Vips::Image.new_from_buffer(character, "", access: 'sequential', n: -1)
aura = File.open("aura.gif").read
aura_b = Vips::Image.new_from_buffer(aura, "", access: 'sequential', n: -1)
aura_b.composite(character_b, "over", x: 0, y: 0).webpsave("composite.gif") Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
After digging around a bit more I realized that Vips models animated images as a huge image so I ended up with this code which does what I need: require 'vips'
character = File.open("character.webp").read
character_b = Vips::Image.new_from_buffer(character, "")
aura = File.open("aura.webp").read
aura_b = Vips::Image.new_from_buffer(aura, "", access: 'sequential', n: -1)
page_h = aura_b.get("height") / aura_b.get("n-pages")
aura_b.get("n-pages").times.each do |i|
aura_b = aura_b.composite(character_b, "over", x: 0, y: page_h * i)
end
aura_b.webpsave("composite.webp") |
Beta Was this translation helpful? Give feedback.
-
Hi @slnc, That'll work, but it'll be pretty slow since every pixel will need to pass through a stack of
https://www.rubydoc.info/gems/ruby-vips/Vips/Image#replicate-instance_method It's extremely quick (it just copies pointers), so you can use it instead of any kind of loop over the X and Y dimensions. Something like: require 'vips'
character = Vips::Image.new_from_file(ARGV[0])
aura = Vips::Image.new_from_file(ARGV[1], access: 'sequential')
character = character
.replicate(1, aura.get("n-pages"))
aura
.composite(character, "over")
.write_to_file(ARGV[2]) Then:
To make: |
Beta Was this translation helpful? Give feedback.
-
Argh! Please don't cross post questions. It makes extra unnecessary work for volunteer maintainers. |
Beta Was this translation helpful? Give feedback.
Hi @slnc,
That'll work, but it'll be pretty slow since every pixel will need to pass through a stack of
n_pages
composite operations. A quicker solution would be to copy the charactern_pages
times vertically, then do a singlecomposite
for the whole animation.replicate
tiles images:https://www.rubydoc.info/gems/ruby-vips/Vips/Image#replicate-instance_method
It's extremely quick (it just copies pointers), so you can use it instead of any kind of loop over the X and Y dimensions.
Something like: