Combine Thumbnails to One Large Image with RMagick

后端 未结 1 589
执念已碎
执念已碎 2021-02-09 08:24

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条回答
  •  被撕碎了的回忆
    2021-02-09 08:48

    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")
    

    0 讨论(0)
提交回复
热议问题