Ruby “组合多个图像”;“条子”;使用ChunkyPNG将图像转换为一个图像
我如何使用ChunkyPNG将多个(在本例中为10个)图像“条带”(所有宽度相等)组合成一个图像 现在,我将所有这些图像条存储在一个数组中,在某个时刻,我将不得不根据像素数据排列它们。下面是我的代码的样子:Ruby “组合多个图像”;“条子”;使用ChunkyPNG将图像转换为一个图像,ruby,image,png,rmagick,Ruby,Image,Png,Rmagick,我如何使用ChunkyPNG将多个(在本例中为10个)图像“条带”(所有宽度相等)组合成一个图像 现在,我将所有这些图像条存储在一个数组中,在某个时刻,我将不得不根据像素数据排列它们。下面是我的代码的样子: require 'chunky_png' image = ChunkyPNG::Image.from_file('input.png') width = image.dimension.width currentWidth = 0 strips = [] 20.times do
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
require'chunky_png'
image=ChunkyPNG::image.from_文件('input.png'))
宽度=image.dimension.width
currentWidth=0
条带=[]
20.5倍
image2=image.crop(currentWidth,0,32,359)
试一试:
newpic = newpic.replace(strips[0], offset_x = 0, offset_y = 0)
newpic.save('name.png') # save when done
使用replace方法,可以从阵列中选择任意条带,并根据偏移量将它们放置在画布上。这就是你的想法吗