Thanks
","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"Hi @slnc,
\nThat'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 character n_pages
times vertically, then do a single composite
for the whole animation.
replicate
tiles images:
https://www.rubydoc.info/gems/ruby-vips/Vips/Image#replicate-instance_method
\nIt's extremely quick (it just copies pointers), so you can use it instead of any kind of loop over the X and Y dimensions.
\nSomething like:
\nrequire 'vips'\n\ncharacter = Vips::Image.new_from_file(ARGV[0])\naura = Vips::Image.new_from_file(ARGV[1], access: 'sequential')\n\ncharacter = character\n .replicate(1, aura.get(\"n-pages\"))\naura\n .composite(character, \"over\")\n .write_to_file(ARGV[2])
Then:
\n$ ./x.rb ~/pics/character.gif ~/pics/aura.gif[n=-1] x.gif\n
To make:
\n","upvoteCount":2,"url":"https://github.com/libvips/ruby-vips/discussions/353#discussioncomment-4437000"}}}-
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.
-
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: