From: Tim Hunter Date: 2009-04-29T07:25:23+09:00 Subject: Re: composite gif files with RMagick Wu Junchen wrote: > I have two gif files,and I want to composite them,there is my ruby code: > > require 'rmagick' > include Magick > gif1=ImageList.new('one.gif') > gif2=ImageList.new('two.gif') > dest=ImageList.new > 0.upto(gif1.size-1){|i| > dest << > gif1[i].composite(gif2[i%gif2.size],5,5,CompositeOperator::OverCompositeOp) > } > dest.write('test.gif') > > However,the size of the gif1 frames are not the same: > irb(main):092:0> gif1[0] > => gif.gif=>0.gif GIF 128x128 128x128+0+0 PseudoClass 256c 8-bit 2kb > irb(main):093:0> gif1[1] > => gif.gif=>1.gif GIF 71x73 128x128+29+13 PseudoClass 256c 8-bit 2kb > > the xy-offset can just applied to the frame size,eg:71*73,so if I give > it -29 and -13,I still can't get 128x128+0+0,how can I add all my gif2's > frame to gif1 on 128x128+5+5?And how can I get the x-offset and y-offset > of the gif file,I can't find some method to get the info '29+13'. > > Any help will be appreciated! > > Attachments: > http://www.ruby-forum.com/attachment/3627/gifs.zip > I'm assuming that you want to composite a 71x73 image 5 pixels from the top and 5 pixels from the left over a 128x128 image. Probably the page offset (+29+13) is screwing you up. You can remove the page offset by assigning a new Rectangle to the page attribute. See http://studio.imagemagick.org/RMagick/doc/imageattrs.html#page. Something like img.page = Rectangle.new(0,0,0,0) should do the trick. If you're creating the smaller image by cropping a larger image, and you don't otherwise need the page offsets, you can prevent crop from embedding the page offsets into the cropped image by supplying true as the last argument to crop. See http://studio.imagemagick.org/RMagick/doc/image1.html#crop. Lastly, you can get the page offsets from the page attribute: rect = img.page -- RMagick: http://rmagick.rubyforge.org/