gpt4 book ai didi

ruby - 使用 ChunkyPNG 将多个图像 "strips"合并为一个图像

转载 作者:太空宇宙 更新时间:2023-11-03 16:35:34 33 4
gpt4 key购买 nike

我如何使用 ChunkyPNG 将多个(在本例中为 10 个)图像“ strip ”(全部宽度相等)组合成一个图像?

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

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

我是 ruby​​ 编程和 chunkypng 的新手,所以非常感谢任何帮助。

谢谢。

最佳答案

试试这个:

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

使用 replace 方法,您可以从数组中选择任何 strip ,并根据偏移量将它们放置在 Canvas 上。这是你的想法吗?

关于ruby - 使用 ChunkyPNG 将多个图像 "strips"合并为一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8272836/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com