使用 RMagick 将缩略图合并为一张大图像 [英] Combine Thumbnails to One Large Image with RMagick
本文介绍了使用 RMagick 将缩略图合并为一张大图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 RMagick 将 20 个 256x256 缩略图组合成一个 4 行 x 5 列的大图像的最短方法是什么?
What's the shortest way to combine say 20 256x256 thumbnails into a single large image of 4 rows by 5 columns using RMagick?
推荐答案
假设所有图片都在当前目录下,命名从 1.jpg 到 n.jpg,row * col = n.
Assuming all the images are in the current directory and named from 1.jpg to n.jpg and row * col = n.
include Magick
row = NUM_ROWS
col = NUM_COLS
ilg = ImageList.new
1.upto(col) {|x| il = ImageList.new
1.upto(row) {|y| il.push(Image.read((y + (x-1)*col).to_s + ".jpg").first)}
ilg.push(il.append(false))}
ilg.append(true).write("out.jpg")
这篇关于使用 RMagick 将缩略图合并为一张大图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文