【问题标题】:Composite manipulated images with RMagick使用 RMagick 合成处理过的图像
【发布时间】:2014-08-30 15:34:16
【问题描述】:

我正在尝试从两个原始图像、一个背景和一个叠加层创建一个合成图像,我使用 RMagick 操作如下:

background = ImageList.new("foo.png")
overlay_original = ImageList.new("bar.png")
overlay_resized = overlay_original.resize_to_fit(400,400)
overlay_cropped = overlay_resized.crop(NorthWestGravity, 400, 200)

new_image = ImageList.new
new_image = new_image.composite_layers(background)
new_image = new_image.composite_layers(overlay_cropped)

当我这样做时,它给了我以下错误:ArgumentError: no images in this image list

当我尝试检查 backgroundoverlay_cropped 图像列表(background.lengthoverlay_cropped.length)的长度时,它告诉我 background 图像列表有 1 个图像,但 overlay_cropped 有没有图片:

NoMethodError: undefined method length' for bar.png PNG 640x1096=>400x200 400x400+0+0 DirectClass 8-bit:Magick::Image

关于我做错了什么有什么想法吗?我猜答案很明显。

【问题讨论】:

    标签: ruby image imagemagick image-manipulation rmagick


    【解决方案1】:

    通过将其更改为以下解决问题:

    marketing_image = marketing_image.composite(background, NorthWestGravity, 0, 0, OverCompositeOp)
    marketing_image = marketing_image.composite(overlay_cropped, NorthWestGravity, 327, 126, OverCompositeOp)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多