Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby “组合多个图像”;“条子”;使用ChunkyPNG将图像转换为一个图像_Ruby_Image_Png_Rmagick - Fatal编程技术网

Ruby “组合多个图像”;“条子”;使用ChunkyPNG将图像转换为一个图像

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

我如何使用ChunkyPNG将多个(在本例中为10个)图像“条带”(所有宽度相等)组合成一个图像

现在,我将所有这些图像条存储在一个数组中,在某个时刻,我将不得不根据像素数据排列它们。下面是我的代码的样子:

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方法,可以从阵列中选择任意条带,并根据偏移量将它们放置在画布上。这就是你的想法吗