本文介绍了从Ruby中的图像集合创建拼贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组图像,这些图像已经布置成矩形,看起来像拼贴画。如何在Ruby中拍摄这些图像并从中创建单个图像?

I have a collection of images that have been laid out in a rectangle to look like a collage. How can I take those images and create a single image out of them in Ruby?

例如,我想在图像中放置三个图像,如下所示:

For example I have three images that I want placed in the image as follows:

图片1:(0,0) - (300,400)

Image 1: (0,0) - (300,400)

图片2:(350,0) - ( 500,200)

Image 2: (350, 0) - (500, 200)

图3:(350,220) - (500,400)

Image 3: (350, 220) - (500, 400)

推荐答案

你可以用RMagick尝试这样的事情:

You can try something like this with RMagick:

require 'RMagick'

bg     = Image.read('bg.png') # may be a background image...
image1 = Image.read('image1.png')
image2 = Image.read('image2.png')
image3 = Image.read('image3.png')


bg.composite!(image1,   0,   0, OverCompositeOp)
bg.composite!(image2, 350,   0, OverCompositeOp)
bg.composite!(image3, 350, 220, OverCompositeOp)

bg.write('collage.png')

这篇关于从Ruby中的图像集合创建拼贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 02:20