如何在Ruby中合并图像 [英] How to combine images in Ruby

查看:62
本文介绍了如何在Ruby中合并图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个正方形图像,分别为1,2,3和4,每个图像的大小为2048x2048px.

I have 4 square images, 1,2,3 and 4 each with 2048x2048px.

我需要将它们合并为4096x4096px的图像,如下所示:

I need to combine those into a 4096x4096px image, like this:

 1 2
 3 4

现在我正在使用Gimp手动执行此操作,但是金额处理在不断增长,我想实现一个自动化的解决方案.

Right now I am doing this manually with Gimp, but the amount processing is growing and I would like to implement an automated solution.

在Ruby中有一种简单的方法吗? (可以使用Rails gem或可以在Rails应用程序内部运行的任何shell命令)

Is there an easy way to do this in Ruby? (Rails gem would be ok or any shell command that can be run from inside a Rails app)

推荐答案

尝试:

Try: 'rmagick' gem

require 'rmagick'

image_list = Magick::ImageList.new("image1.png", "image2.png", "image3.png")
image_list.write("combine.png")

您也可以参考此 SO问题 ,它与您的相似.

You can also refer this SO Question it's similar to yours.

这篇关于如何在Ruby中合并图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆