1
美好的一天。 如何在使用Imagemagic的 以下图片中的logo.jpg上强制使用white_rectangle.jpg。
还有一个额外的问题:Ruby的方法可以完成任务。使用图像魔法为图像添加矩形
def (path_to_image)
# impose white_rectangle.jpg on logo
end
美好的一天。 如何在使用Imagemagic的 以下图片中的logo.jpg上强制使用white_rectangle.jpg。
还有一个额外的问题:Ruby的方法可以完成任务。使用图像魔法为图像添加矩形
def (path_to_image)
# impose white_rectangle.jpg on logo
end
这可以很容易使用RMagick来完成:
require 'RMagick'
logo = Magick::Image.read("logo.jpg").first
rect = Magick::Image.read("white_rectangle.jpg").first
result = logo.composite(rect, x, y, Magick::CopyCompositeOp)
result.write "result.jpg"
一种替代方法是只画一个白色矩形不使用合成图像:
image = Magick::Image.read("logo.jpg").first
gc = Magick::Draw.new
gc.stroke = 'white'
gc.fill = 'white'
gc.rectangle x_start, y_start, x_end, y_end
gc.draw(image)
image.write "result.jpg"
使用ImageMagick命令行工具,可以结束打一个像这样的另一个像这样:
$ composite white_rectangle.jpg logo.jpg -geometry +x+y result.jpg
什么参数(rect,x,y)应该为我附加的图像设置? – itsnikolay 2012-07-13 10:25:13
'rect'是在white_rectangle.jpg中保存实际图像的对象。对于这个职位,只是试验,直到你做对了。 – 2012-07-13 10:42:45