下面的 imageMagick 命令会将一个 Sprite 图像裁剪成几个均分的图像:
convert image.png -crop 2x3-40-20@ +repage +adjoin tile-%d.jpg
我如何使用 Rmagick 执行此操作?但是我不需要创建多个文件,而是需要返回一组图像。
最佳答案
设法通过一次裁剪每个图像来完成它:
def split_images
#'image' is a ImageMagick Object
width = image.cols/number_cols
height = image.rows/nubmer_rows
images = []
0.upto(number_rows-1) do |x|
0.upto(number_cols-1) do |y|
images << image.crop( Magick::NorthWestGravity, x*width, y*height, width, height, true)
end
end
end
关于ruby - RMagick - 如何将网格图像裁剪成图像数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12354222/