initWithStyle
initWithStyle

Reputation: 337

Combine multiple image "strips" into one image with ChunkyPNG

How would I combine multiple (in this case 10) image "strips" (all of equal width) into one image with ChunkyPNG?

Right now, I have all of these image strips stored in an array, and at some point I am going to have to arrange them based on pixel data. Here is what my code looks like:

require 'chunky_png'

image = ChunkyPNG::Image.from_file('input.png')

width = image.dimension.width
currentWidth = 0
strips = []

20.times do
    image2 = image.crop(currentWidth, 0, 32, 359)
    strips << image2
    currentWidth += 32
end

I am new to ruby programming and chunkypng, so any help is greatly appreciated.

Thanks.

Upvotes: 2

Views: 1118

Answers (1)

Brian Fearn
Brian Fearn

Reputation: 51

Try this:

newpic = newpic.replace(strips[0], offset_x = 0, offset_y = 0)
newpic.save('name.png') # save when done

With the replace method, you can select any of the strips from your array and lay them down on a canvas according to the offsets. Is that what you had in mind?

Upvotes: 1

Related Questions