Skip to content
\n

Thanks

","upvoteCount":1,"answerCount":3,"acceptedAnswer":{"@type":"Answer","text":"

Hi @slnc,

\n

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 character n_pages times vertically, then do a single composite for the whole animation.

\n

replicate tiles images:

\n

https://www.rubydoc.info/gems/ruby-vips/Vips/Image#replicate-instance_method

\n

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.

\n

Something like:

\n
require '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])
\n

Then:

\n
$ ./x.rb ~/pics/character.gif ~/pics/aura.gif[n=-1] x.gif\n
\n

To make:

\n

\"x\"

","upvoteCount":2,"url":"https://github.com/libvips/ruby-vips/discussions/353#discussioncomment-4437000"}}}

How to overlay and repeat non-animated image over an animated one? #353

Answered by jcupitt
slnc asked this question in Q&A
Discussion options

You must be logged in to vote

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 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

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
    

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@slnc
Comment options

Answer selected by slnc
Comment options

You must be logged in to vote
3 replies
@slnc
Comment options

@jcupitt
Comment options

@slnc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants